[英]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.