国产探花免费观看_亚洲丰满少妇自慰呻吟_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教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 麦盖提县| 宁都县| 英超| 合肥市| 湾仔区| 木兰县| 修武县| 赤城县| 石渠县| 潜江市| 霍城县| 勃利县| 拉孜县| 大足县| 喀喇沁旗| 高要市| 郓城县| 怀化市| 且末县| 太保市| 盈江县| 公安县| 大港区| 桐梓县| 当涂县| 日喀则市| 凤山县| 苍南县| 甘孜县| 宁国市| 湖南省| 丽江市| 维西| 邵阳市| 习水县| 甘南县| 潜江市| 彝良县| 香港 | 临漳县| 丹巴县|