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 want 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 .
There are two ways to return NULL from an ActionResult (Action Method): 1. Using EmptyResult class. In order to learn more about EmptyResult class, please refer my article ASP.Net MVC EmptyResult Example: Return NULL (Nothing) from Controller to View.
HttpStatusCodeResult(HttpStatusCode, String) Initializes a new instance of the HttpStatusCodeResult class using a status code and status description. HttpStatusCodeResult(Int32) Initializes a new instance of the HttpStatusCodeResult class using a status code.
An action result is what a controller action returns in response to a browser request. The ASP.NET MVC framework supports several types of action results including: ViewResult - Represents HTML and markup. EmptyResult - Represents no result.
return instance of EmptyResult class
return new EmptyResult();
You can return EmptyResult to return an empty view.
public ActionResult Empty()
{
return new EmptyResult();
}
You can also just return null
. ASP.NET will detect the return type null
and will return an EmptyResult for you.
public ActionResult Empty()
{
return null;
}
See MSDN documentation for ActionResult for list of ActionResult types you can return.
if you want to return nothing you can do something like
if (!returnValue)
return Content("");
return View(RealView);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With