這篇文章主要為大家展示了“mvc重定向方式的示例分析”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“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 });
}也可以自己設(shè)置
public ActionResult UrlTest7()
{//可設(shè)置
return new RedirectToRouteResult("Article", new System.Web.Routing.RouteValueDictionary(new { id = 7 }), false) { };
}
public ActionResult UrlTest8()
{//可設(shè)置
return new RedirectResult("/Article/Detial/8", false);
}要注意的是,在View()中指定不同的視圖不是重定向
public ActionResult UrlTest9()
{//200
return View("Detial", null, new { id = 9 });
}第二個代碼段和第三個代碼段中的方法,都會用第四個代碼段中的形式最后以Response.Redirect方法返回給客戶端
以上是“mvc重定向方式的示例分析”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
當(dāng)前標(biāo)題:mvc重定向方式的示例分析-創(chuàng)新互聯(lián)
URL標(biāo)題:http://www.chinadenli.net/article32/dodpsc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網(wǎng)站、外貿(mào)網(wǎng)站建設(shè)、企業(yè)建站、網(wǎng)站導(dǎo)航、面包屑導(dǎo)航、定制網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容