ASP.NET MVC returns empty view

What is the most natural way to return an empty ActionResult (for a child action)?

public ActionResult TestAction(bool returnValue) { if (!returnValue) return View(EmptyView); return View(RealView); } 

One of the options that I see is to create an empty view and reference it in the EmptyView ... but maybe there is some built-in option?

+85
asp.net-mvc
Jul 28 '11 at 10:38
source share
3 answers

returns an instance of the class EmptyResult

  return new EmptyResult(); 
+182
Jul 28 2018-11-11T00:
source share

You can return EmptyResult to return an empty view.

  public ActionResult Empty() { return new EmptyResult(); } 

In principle, you can even return null . The structure will determine the return type null and return EmptyResult for you .

  public ActionResult Empty() { return null; } 

See the MSDN documentation for ActionResult for a list of ActionResult types that you can return.

+11
Mar 23 '15 at 6:29
source share

If you want to return nothing, you can do something like

 if (!returnValue) return Content(""); return View(RealView); 
+7
Jul 28 2018-11-11T00:
source share



All Articles