[英]Trouble with MVC 5 and ambient route parameters
在上面的項目(MVC 5)中,我遇到了Html.ActionLink問題,似乎沒有從當前頁面清除路由參數。
一頁上對Html.ActionLink的完全相同的調用會產生不同的結果,具體取決於您對路線的“深度”。 以下是我的示例控制器
// GET: Sample
public ActionResult Index()
{
return View("Index");
}
[Route("sample/example/{categoryid}")]
public ActionResult Example(int categoryID)
{
ViewBag.categoryID = categoryID;
return View("Example");
}
[Route("sample/example/{parentcategoryid:int}/{categorydepth:int}")]
public ActionResult Example(int parentcategoryID, int categorydepth)
{
ViewBag.parentcategoryID = parentcategoryID;
ViewBag.categorydepth = categorydepth;
return View("Example");
}
以下是“樣本/索引”視圖中的摘錄
@Html.ActionLink("Link", "Example", new { controller = "Sample", categoryid = 100 }, null)
這將產生以下HTML: http://localhost:2762/sample/example/100
以下是“示例/示例”視圖中的摘錄
@Html.ActionLink("Link", "Example", new { controller = "Sample", categoryid = 100 }, null)
<br />
@Html.ActionLink("Deeper Link", "Example", new { controller="Sample", parentcategoryid=9999, categorydepth=2})
第一次通過單擊“索引”視圖中的鏈接到達那里時,“鏈接” HTML相同: http://localhost:2762/sample/example/100
如果單擊“ Deeper Link”,您將再次獲得相同的視圖...但是,“ Link” HTML現在為: http://localhost:2762/sample/example/9999/2?categoryid=100
顯然不會顯示您想去的地方。
這基本上是瀏覽產品類別的面包屑場景。
關於此問題的干凈且可管理的修復有什么想法?
在控制器中將Example()更改為Example2()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.