Difference Between ViewResult() and ActionResult()

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

    In the Controller , one could use the below syntax

    public ViewResult EditEmployee() {
        return View();
    }
    
    public ActionResult EditEmployee() {
        return View();
    }
    

    In the above example , only the return type varies . one returns ViewResult whereas the other one returns ActionResult.

    ActionResult is an abstract class . It can accept:

    ViewResult , PartialViewResult, EmptyResult , RedirectResult , RedirectToRouteResult , JsonResult , JavaScriptResult , ContentResult, FileContentResult , FileStreamResult , FilePathResult etc.

    The ViewResult is a subclass of ActionResult.

提交回复
热议问题