Must ASP.NET MVC Controller Methods Return ActionResult?

前端 未结 6 739
情书的邮戳
情书的邮戳 2020-12-02 14:24

Being new to ASP.NET MVC, I\'ve been wondering about the signature of Controller methods. In all the examples I\'ve seen, they always seem to return ActionResult, even if th

6条回答
  •  Happy的楠姐
    2020-12-02 14:53

    Always return the most accurate type you can return. So you should return a ViewResult when the action always shows a view. I would only use ActionResult when you return in ViewResult in some cases (invalid posted data) or a RedirectToRouteResult in other cases.

    With some advanced actionfilter/executing scenario's, you can even return totally different things that have nothing to do with ActionResult.

提交回复
热议问题