ActionResult

定义在Controller中的Action方法大都返回一个ActionResult对象。ActionResult是对Action执行结果的封装,用于最终对请求进行响应。ActionResult是控制器方法执行后返回的结果类型,控制器方法可以返回一个直接或间接从ActionResult抽象类继承的类型。

ViewResult:

表示一个视图结果,它根据视图模板产生应答内容。对应Controller方法为View。

    public ActionResult Index(int id = 1)
        {
            var model = db.U_SP_AuditLog.OrderBy(a =>        a.ChangedOn).ToPagedList(id, 10);
            return View(model);
        }

PartialViewResult:

表示一个部分视图结果,与ViewResult本质上一致,只是部分视图不支持母版,对应于ASP.NET,ViewResult相当于一个Page,而 PartialViewResult则相当于一个UserControl。它对应的Controller方法为PartialView。

JsonResult:

表示一个序列化的JSON结果。MVC将Response.ContentType设置为application/json,并通过 JavaScriptSerializer类将指定对象序列化为Json表示方式。需要注意,默认情况下,MVC不允许GET请求返回JSON结果,要解除此限制,在生成JsonResult对象时,将其JsonRequestBehavior属性设置为 JsonRequestBehavior.AllowGet。此结果对应的Controller方法为Json。

 class CityData { public string city; public int temperature; } 
 public JsonResult WeatherData() 
 { 
     var citiesArray = new[] { 
         new CityData { city = "London", temperature = 68 }, 
         new CityData { city = "Hong Kong", temperature = 84 } 
     }; 
     return Json(citiesArray); 
 }

RedirectResult:

表示一个连接跳转,相当于ASP.NET中的Response.Redirect方法。对应的Controller方法为Redirect。

public override void ExecuteResult(ControllerContext context) {
     if (context == null) {
         throw new ArgumentNullException("context");
     }
     if (context.IsChildAction) {
         throw new InvalidOperationException(MvcResources.RedirectAction_CannotRedirectInChildAction);
     }
     string destinationUrl = UrlHelper.GenerateContentUrl(Url, context.HttpContext);
     context.Controller.TempData.Keep();
     context.HttpContext.Response.Redirect(destinationUrl, false /* endResponse */);
 }

JavaScriptResult:

本质上是一个文本内容,只是将Response.ContentType设置为application/x-javascript,此结果应该和MicrosoftMvcAjax.js脚本配合使用,客户端接收到Ajax应答后,将判断Response.ContentType的值,如果是application/x-javascript,则直接eval执行返回的应答内容。此结果类型对应的Controller方法为JavaScript。

原文地址:https://www.cnblogs.com/chrisghb8812/p/5585278.html