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

首頁 > 服務器 > 管理維護 > 正文

mvc重定向方式詳解

2024-09-10 14:20:02
字體:
來源:轉載
供稿:網友

本文實例為大家分享了mvc重定向的幾種方式,供大家參考,具體內容如下

在RouteConfig添加一個簡單的路由

//新增路由 routes.MapRoute( name: "Article", url: "Detial/{id}", defaults: new { controller = "Article", action = "Detial", id = UrlParameter.Optional }, constraints: new { id = @"/d+" } //namespaces: new string[] { });

302重定向

public ActionResult UrlTest1() {//302  return Redirect("/Article/Detial/1"); } public ActionResult UrlTest2() {//302 return RedirectToAction("Detial", "Article", new System.Web.Routing.RouteValueDictionary(new { id = 2 })); //return RedirectToAction("Detial", "Article",new { id = 1}); } public ActionResult UrlTest3() {//302 return RedirectToRoute("Article", new System.Web.Routing.RouteValueDictionary(new { id = 3 })); //return RedirectToRoute("Article", new { id = 1 });}

301重定向 

  public ActionResult UrlTest4() {//301   return RedirectPermanent("/Article/Detial/4");  }  public ActionResult UrlTest5()  {//301   return RedirectToActionPermanent("Detial", "Article", new System.Web.Routing.RouteValueDictionary(new { id = 5 }));   //return RedirectToActionPermanent("Detial", "Article", new { id = 1 });  }  public ActionResult UrlTest6()  {//301   return RedirectToRoutePermanent("Article", new System.Web.Routing.RouteValueDictionary(new { id = 6 }));   //return RedirectToRoutePermanent("Article", new { id = 1 });  }

也可以自己設置

 public ActionResult UrlTest7() {//可設置  return new RedirectToRouteResult("Article", new System.Web.Routing.RouteValueDictionary(new { id = 7 }), false) { }; } public ActionResult UrlTest8() {//可設置  return new RedirectResult("/Article/Detial/8", false); }

要注意的是,在View()中指定不同的視圖不是重定向

 public ActionResult UrlTest9() {//200  return View("Detial", null, new { id = 9 }); }

第二個代碼段和第三個代碼段中的方法,都會用第四個代碼段中的形式最后以Response.Redirect方法返回給客戶端

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持錯新站長站。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 怀来县| 克山县| 贵港市| 冕宁县| 泸西县| 华蓥市| 廊坊市| 年辖:市辖区| 密山市| 泾阳县| 双鸭山市| 怀柔区| 嘉兴市| 光泽县| 阳谷县| 沛县| 洛阳市| 上栗县| 南溪县| 友谊县| 克拉玛依市| 南宁市| 稷山县| 吐鲁番市| 兴隆县| 黑龙江省| 长乐市| 甘德县| 山阴县| 遂川县| 安乡县| 鄢陵县| 兴隆县| 阿图什市| 潼南县| 武清区| 兴隆县| 葵青区| 赣榆县| 昌江| 胶南市|