国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > WEB開發 > 正文

MVC(六、ActionResult 返回類型 )

2024-04-27 15:19:46
字體:
來源:轉載
供稿:網友

1、ActionResult簡介

ActionResult是一個抽象類, 在Action中返回的都是其派生類。 ActionResult派生類:

類名 抽象類 父類 功能
ContentResult 根據內容的類型和編碼,數據內容
EmptyResult 空方法
FileResult abstract 寫入文件內容,具體的寫入方式在派生類中
FileContentResult FileResult 通過 文件byte[] 寫入文件
FilePathResult FileResult 通過 文件路徑 寫入文件
FileStreamResult FileResult 通過 文件Stream 寫入文件
HttpUnauthorizedResult 拋出401錯誤
javaScriptResult 返回Javascript文件
JsonResult 返回Json格式的數據
RedirectResult 使用Response.Redirect重定向頁面
RedirectToRouteResult 根據Route規則重定向頁面
ViewResultBase abstract 調用IView.Render()
PartialViewResult ViewResultBase 調用父類ViewResultBase 的ExecuteResult方法. 重寫了父類的FindView方法. 尋找用戶控件.ascx文件
ViewResult ViewResultBase 同上

2、ViewResult

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

3、ContentResult

public ActionResult ContentResult() { return Content("Hi, 我是ContentResult結果"); }

4、EmptyResult

public ActionResult EmptyResult() {   //空結果當然是空白了!   //至于你信不信, 我反正信了   return new EmptyResult(); }

5、FileResult

public ActionResult FileResult() {   var imgPath = Server.MapPath("~/demo.jpg");   return File(imgPath, "application/x-jpg", "demo.jpg"); }

6、HttpNotFoundResult

public ActionResult HttpNotFoundResult() {   return HttpNotFound("Page Not Found"); }

7、HttpUnauthorizedResult

public ActionResult HttpUnauthorizedResult() {   //未驗證時,跳轉到Logon   return new HttpUnauthorizedResult(); }

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); }

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(); }
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 凌源市| 惠水县| 环江| 健康| 本溪市| 青龙| 内乡县| 花莲市| 扬中市| 高碑店市| 得荣县| 柞水县| 贵德县| 紫阳县| 景宁| 虞城县| 同德县| 内乡县| 乳源| 饶河县| 庐江县| 融水| 永济市| 正安县| 白沙| 靖边县| 平遥县| 临猗县| 基隆市| 恭城| 洪雅县| 兴山县| 桂东县| 漳浦县| 淮安市| 精河县| 资兴市| 读书| 石台县| 佳木斯市| 蓝山县|