MVC controller returns many types of output to the view . In this article we will learn
about EmptyResult return type of MVC . So instead of going into the
depth on the subject, let us start with its practical implementation.
To know more about the Action result types please refer my previous article
What is ActionResult ?
It is one of the type of output format in ASP.NET MVC which is shown to the client .
What is EmptyResult ?
The EmptyResult is a class in MVC which does not return anything at client site ,its just like Void method .
EmptyResult is used when you wants to execute logic return inside the controller action method but does not want any result back to the view then EmptyResult return type is very important .
Key points
It is one of the type of output format in ASP.NET MVC which is shown to the client .
What is EmptyResult ?
The EmptyResult is a class in MVC which does not return anything at client site ,its just like Void method .
EmptyResult is used when you wants to execute logic return inside the controller action method but does not want any result back to the view then EmptyResult return type is very important .
Key points
- It does not return any output to the browser .
- It shows the empty result set to the browser without any adding the view .
- Does not require to add the view
Methods of EmptyResult The following are the methods of EmptyResult class
- Equals : This method is used to check whether the two objects are equal or not.
- ExecuteResult : This method is used to execute the specific result context.
- Finalize : This method is used to free the memory which is occupied by object and allow to allocate another object in freed memory .
- GetHashCode: It is used to get the numeric value which is used to identify and insert an object in hash based collection.
- GetType : This method is used to check the what is the type of object .
- MemberwiseClone: This method is used to create the shallow copy of the current object .
- ToString : This method is used to convert the current result to the string .
Step 1 : Create an MVC application
Step 3 : Add controller class- "Start", then "All Programs" and select "Microsoft Visual Studio 2015".
- "File", then "New" and click "Project" then select "ASP.NET Web Application Template", then provide the Project a name as you wish and click on OK.
- Choose MVC empty application option and click on OK
Right click on Controller folder in the created MVC application ,give the class name Home or as you
and click on OK
HomeControlle.cs
public class HomeController : Controller { // GET: for main view public EmptyResult EmptyData() { return new EmptyResult(); } }
Lets run the application and see the output.
From above examples we have learned about the EmptyResult return type and its use.
Summary
I hope this article is useful for all the readers. If you have any suggestion please contact me.
Download Aspose : API To Create and Convert Files
Post a Comment