Wednesday, 3 February 2016

EmptyResult Return Type In ASP.NET MVC

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 .
I hope you have understand about the EmptyResult  type from preceding brief summary ,now let's implement its practically.
Step 1 : Create an MVC application
  1. "Start", then "All Programs" and select "Microsoft Visual Studio 2015".
  2. "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.
  3. Choose MVC empty application option and click on OK
Step 3 : Add controller class
Right click on Controller folder in the created MVC application ,give the class name Home or as you 
and click on OK
public class HomeController : Controller
        // GET: for main view
        public EmptyResult EmptyData()
        return new EmptyResult();
In the above controller class we have added to action method that is EmptyData which returns EmptyResult means nothing .
Lets run the application and see the output.

From above examples we have learned about the  EmptyResult return type and its use.

No comments:

Post a Comment

Row based styling for Primeng DataTable using Angualr 2,4

------------------------------------Component.Html---------------- < p -dataTable id = "Tbl" [ rowStyleClass ]= " Fu...