我使用MvcSiteMapProvider在Asp.net MVC 4中创建treeview导航器
我有2个链接:
〜/ Home / Article / {id}和 〜/主页/图库/ {id}
我的Treeview像:主页 - >文章 - >画廊
我在Controller上使用了动态代码
[MvcSiteMapNode(Title = "Article", ParentKey = "Home", Key="Article", PreservedRouteParameters="id")]
public ActionResult Article(int id)
{
ViewBag.Id = id;
return View();
}
[MvcSiteMapNode(Title = "Gallery", Key="Gallery" ParentKey = "Article", PreservedRouteParameters="id")]
public ActionResult Gallery(int id)
{
ViewBag.id = id;
return View();
}
所以它运行成功,但问题是我什么时候 〜/ Home / Article / 123我去〜/ Home / Gallery / 456
接下来我点击树视图返回文章,它在文章中设置了错误的ID参数,它为文章的ID设置了图库ID:〜/ Home / Article / 456。
任何人都有解决者?抱歉我的英语很糟糕。
答案 0 :(得分:0)
您可以明确设置参数的名称。
例如
[MvcSiteMapNode(Title = "Article", ParentKey = "Home", Key="Article", PreservedRouteParameters="ArticleId")]
public ActionResult Article(int ArticleId)
{
ViewBag.Id = ArticleId;
return View();
}
[MvcSiteMapNode(Title = "Gallery", Key="Gallery" ParentKey = "Article", PreservedRouteParameters="GalleryId")]
public ActionResult Gallery(int GalleryId)
{
ViewBag.id = GalleryId;
return View();
}
然后:
/Home/Article/123
/Home/Gallery?GalleryId=456&ArticleId=123