Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC return empty view

Tags:

asp.net-mvc

People also ask

How to return Empty result in MVC?

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 .

How do I return nothing in ActionResult?

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.

What is HttpStatusCodeResult?

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.

What are action results in MVC?

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);