MVC(六、ActionResult 返回類型 )
2/10/2017來源:心得技巧人氣:20553
男人的天堂 AV电影1、ActionResult簡介
ActionResult是一個抽象類, 在Action中返回的都是其派生類。 ActionResult派生類:
類名 | 抽象類 | 父類 | 功能 |
---|---|---|---|
ContentResult | 根據內容的類型和編碼,數據內容 | ||
EmptyResult | 空方法 | ||
FileResult | abstract | 寫入文件內容,具體的寫入方式在派生類中 | |
FileContentResult | FileResult | 通過 文件byte[] 寫入文件 | |
FilePathResult | FileResult | 通過 文件路徑 寫入文件 | |
FileStreamResult | FileResult | 通過 文件Stream 寫入文件 | |
HttpUnauthorizedResult | 拋出401錯誤 | ||
javaScrtResult | 返回Javascript文件 | ||
JsonResult | 返回Json格式的數據 | ||
RedirectResult | 使用Response.Redirect重定向頁面 | ||
RedirectToRouteResult | 根據Route規則重定向頁面 | ||
ViewResultBase | abstract | 調用IView.Render() | |
PartialViewResult | ViewResultBase | 調用父類ViewResultBase 的ExecuteResult方法. 重寫了父類的FindView方法. 尋找用戶控件.ascx文件 | |
ViewResult | ViewResultBase | 同上 |
男人的天堂 AV电影2、ViewResult
public ActionResult ViewResult() { return View(); }男人的天堂 AV电影3、ContentResult
public ActionResult ContentResult() { return Content("Hi, 我是ContentResult結果"); }4、EmptyResult
public ActionResult EmptyResult() { //空結果當然是空白了! //至于你信不信, 我反正信了 return new EmptyResult(); }男人的天堂 AV电影5、FileResult
public ActionResult FileResult() { var imgPath = Server.MapPath("~/demo.jpg"); return File(imgPath, "application/x-jpg", "demo.jpg"); }男人的天堂 AV电影6、HttpNotFoundResult
public ActionResult HttpNotFoundResult() { return HttpNotFound("Page Not Found"); }男人的天堂 AV电影7、HttpUnauthorizedResult
public ActionResult HttpUnauthorizedResult() { //未驗證時,跳轉到Logon return new HttpUnauthorizedResult(); }男人的天堂 AV电影8、JavaScriptResult
public ActionResult JavaScriptResult() { string js = "alert(\"Hi, I'm JavaScript.\");"; return JavaScript(js); }9、JsonResult
public ActionResult JsonResult() { var jsonObj = new { Id = 1, Name = "小銘", Sex = "男", Like = "足球" }; return Json(jsonObj, JsonRequestBehavior.AllowGet); }男人的天堂 AV电影10、RedirectResult
public ActionResult RedirectResult() { return Redirect("~/demo.jpg"); }11、RedirectToRouteResult
public ActionResult RedirectToRouteResult() { return RedirectToRoute(new { controller = "Hello", action = "" }); }12、PartialViewResult
public ActionResult PartialViewResult() { return PartialView(); }優質網站模板
- 1
- 2
- 3
最新文章推薦