在上面的项目中(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");
}
以下是Sample / Index视图的片段
@Html.ActionLink("Link", "Example", new { controller = "Sample", categoryid = 100 }, null)
这会生成以下HTML:http://localhost:2762/sample/example/100
以下是Sample / Example视图的片段
@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
如果您点击“更深层次的链接”,您会再次获得相同的视图...但是“链接”Html现在是:http://localhost:2762/sample/example/9999/2?categoryid=100
显然没有您希望它去的地方。
这基本上是浏览产品类别的面包屑方案。
对于干净且易于管理的解决方案的任何想法?
答案 0 :(得分:0)
将控制器中的Example()更改为Example2()