SiteMapMvc 无法使用静态中的两个参数 url
SiteMapMvc not working With two parameters in static url
我的 Asp.net Mvc 应用程序中有路由配置,如下所示:
路由配置
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Default2",
url: "{controller}/{action}/{id}/{title}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional, title = UrlParameter.Optional }
);
}
我有三个控制器:Articles、DevSection 和 Home
[SiteMapTitle("title")]
public ActionResult Index(int id, string title)
{
objlstproc = getproc();
Proc objproc = objlstproc.Find(s => s.id == id);
return View(objproc);
}
我的站点地图代码是
<mvcSiteMapNode title="Home" controller="Home" action="Index">
<mvcSiteMapNode title="DevSection" controller="DevSection" action="Index" key="DevSection">
<mvcSiteMapNode title="Articles" controller="DevSection" action="Article" key="Articles">
<mvcSiteMapNode title="" controller="Articles" action="Index" preservedRouteParameters="id,title" />
</mvcSiteMapNode>
</mvcSiteMapNode>
现在我使用来自
@Html.MvcSiteMap().SiteMapPath()
在我的布局中,出现此错误
The node with key 'Articles_Articles_Index_GET__' does not have a 'title' set. Title is a required field for every node.
所以我使用 xxx 字符串为下方行的标题设置默认字符串
<mvcSiteMapNode title="xxx " controller="Articles" action="Index" preservedRouteParameters="id,title" />
现在可以正常工作应用程序了,现在我想使用此 url 转到 Articles Controller 和 Index 操作:
http://localhost:3754/Articles/index/1/whatever
我收到这个错误
The node with key 'Articles_Articles_Index_GET_xxx_' may not add a route value with the key 'title' and value 's' to the RouteValues dictionary because the key is a reserved name. Reserved names are keys that are meant for use internally by MvcSiteMapProvider rather than a dictionary value.
有效键可以是 "area"、"controller"、"action" 以及与 属性 ISiteMapNode 名称不同的自定义参数。
您可以通过调用接受 'throwIfReservedKey' 参数的 RouteValues.Add() 或 RouteValues.AddRange() 的重载并为值传递 false 来抑制此错误消息。请注意,如果您这样做,尝试将具有保留名称的键添加到 RouteValues 字典将会失败。
但是如果我使用来自 http://localhost:3333/Articles/index/1
或者
http://localhost:3333/Articles/index?id=1&&titile=ds
站点地图对我来说很好...
但我只想使用 from
http://localhost:3754/Articles/index/1/whatever
在我的网站上。
感恩
我将标题名称更改为 t(随便)。因为标题是站点地图中的关键字或保留内容,并且与我的路线标题冲突,例如:url: "{controller}/{action}/{id}/{t}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional, t = UrlParameter.Optional } 不要谢我,谢天谢地
我的 Asp.net Mvc 应用程序中有路由配置,如下所示:
路由配置
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Default2",
url: "{controller}/{action}/{id}/{title}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional, title = UrlParameter.Optional }
);
}
我有三个控制器:Articles、DevSection 和 Home
[SiteMapTitle("title")]
public ActionResult Index(int id, string title)
{
objlstproc = getproc();
Proc objproc = objlstproc.Find(s => s.id == id);
return View(objproc);
}
我的站点地图代码是
<mvcSiteMapNode title="Home" controller="Home" action="Index">
<mvcSiteMapNode title="DevSection" controller="DevSection" action="Index" key="DevSection">
<mvcSiteMapNode title="Articles" controller="DevSection" action="Article" key="Articles">
<mvcSiteMapNode title="" controller="Articles" action="Index" preservedRouteParameters="id,title" />
</mvcSiteMapNode>
</mvcSiteMapNode>
现在我使用来自
@Html.MvcSiteMap().SiteMapPath()
在我的布局中,出现此错误
The node with key 'Articles_Articles_Index_GET__' does not have a 'title' set. Title is a required field for every node.
所以我使用 xxx 字符串为下方行的标题设置默认字符串
<mvcSiteMapNode title="xxx " controller="Articles" action="Index" preservedRouteParameters="id,title" />
现在可以正常工作应用程序了,现在我想使用此 url 转到 Articles Controller 和 Index 操作:
http://localhost:3754/Articles/index/1/whatever
我收到这个错误
The node with key 'Articles_Articles_Index_GET_xxx_' may not add a route value with the key 'title' and value 's' to the RouteValues dictionary because the key is a reserved name. Reserved names are keys that are meant for use internally by MvcSiteMapProvider rather than a dictionary value.
有效键可以是 "area"、"controller"、"action" 以及与 属性 ISiteMapNode 名称不同的自定义参数。
您可以通过调用接受 'throwIfReservedKey' 参数的 RouteValues.Add() 或 RouteValues.AddRange() 的重载并为值传递 false 来抑制此错误消息。请注意,如果您这样做,尝试将具有保留名称的键添加到 RouteValues 字典将会失败。
但是如果我使用来自 http://localhost:3333/Articles/index/1 或者 http://localhost:3333/Articles/index?id=1&&titile=ds
站点地图对我来说很好...
但我只想使用 from http://localhost:3754/Articles/index/1/whatever 在我的网站上。
感恩
我将标题名称更改为 t(随便)。因为标题是站点地图中的关键字或保留内容,并且与我的路线标题冲突,例如:url: "{controller}/{action}/{id}/{t}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional, t = UrlParameter.Optional } 不要谢我,谢天谢地