ASP.NET MVC return empty view

后端 未结 3 1331
日久生厌
日久生厌 2020-12-28 11:27

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

public ActionResult TestAction(bool returnValue)
{
   if (!returnValue)
             


        
相关标签:
3条回答
  • 2020-12-28 11:51

    if you want to return nothing you can do something like

    if (!returnValue)
         return Content("");
    
       return View(RealView);
    
    0 讨论(0)
  • 2020-12-28 11:54

    return instance of EmptyResult class

     return new EmptyResult();
    
    0 讨论(0)
  • 2020-12-28 11:55

    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.

    0 讨论(0)
提交回复
热议问题