开发者

ASP.NET MVC return empty view

开发者 https://www.devze.com 2023-03-23 07:15 出处:网络
What is the most natural way to return an empty ActionResult (for child action)? public ActionResult TestAction(b开发者_如何学Goool returnValue)

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

public ActionResult TestAction(b开发者_如何学Goool returnValue)
{
   if (!returnValue)
     return View(EmptyView);

   return View(RealView);
}

One option I can see is to create an empty view and reference it at EmptyView... but may be there is any built-in option?


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号