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

首頁 > 編程 > .NET > 正文

mvc重定向方式詳解

2024-07-10 13:32:03
字體:
來源:轉載
供稿:網友

本文實例為大家分享了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方法返回給客戶端

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VeVb武林網。


注:相關教程知識閱讀請移步到ASP.NET教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 游戏| 临泉县| 新兴县| 龙泉市| 寻乌县| 县级市| 文山县| 渭南市| 团风县| 舞钢市| 施秉县| 正定县| 唐山市| 阿勒泰市| 顺义区| 天全县| 阿鲁科尔沁旗| 呼伦贝尔市| 惠水县| 南昌市| 赤城县| 皋兰县| 客服| 泗阳县| 中超| 祁阳县| 睢宁县| 茌平县| 云安县| 武威市| 北辰区| 贺州市| 盐池县| 河东区| 民权县| 民丰县| 新巴尔虎左旗| 德格县| 木里| 马关县| 永安市|