Difference Between ViewResult() and ActionResult()

后端 未结 8 1134
忘掉有多难
忘掉有多难 2020-11-30 16:02

What is the difference between ViewResult() and ActionResult() in ASP.NET MVC?

public ViewResult Index()
{
    return View();
}

pu         


        
8条回答
  •  感动是毒
    2020-11-30 16:25

    While other answers have noted the differences correctly, note that if you are in fact returning a ViewResult only it is better to return the more specific type rather than the base ActionResult type. An obvious exception to this principle is when your method returns multiple types deriving from ActionResult.

    For a full discussion of the reasons behind this principle please see the related discussion here: Must ASP.NET MVC Controller Methods Return ActionResult?

提交回复
热议问题