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
Right click on Controller folder in the created MVC application ,give the class name Home or as you
and click on OK
HomeControlle.cs
In the above controller class we have added to action
method that is EmptyData which returns EmptyResult means nothing .
From above examples we have learned about the EmptyResult return type and its use.
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.
0 Comments