Difference Between ViewResult() and ActionResult()

后端 未结 8 1124
忘掉有多难
忘掉有多难 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:40

    It's for the same reason you don't write every method of every class to return "object". You should be as specific as you can. This is especially valuable if you're planning to write unit tests. No more testing return types and/or casting the result.

提交回复
热议问题