SiteMapMvc无法使用静态URL中的两个参数

时间:2016-08-15 06:38:44

标签: asp.net-mvc routing sitemap

我在Asp.net Mvc应用程序中有Route Config,如下所示:

RouteConfig

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 }
      );
    } 

我有三个控制器:文章 DevSection 主页

  [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()

在我的布局中,我收到此错误

  

带有键&#39; Articles_Articles_Index_GET __&#39;的节点没有标题&#39;组。标题是每个节点的必填字段。

所以我为下面的行设置xxx字符串的标题的默认字符串

 <mvcSiteMapNode title="xxx "  controller="Articles" action="Index" preservedRouteParameters="id,title" />

现在工作申请正常,现在我想用这个网址转到文章控制器和索引操作:

http://localhost:3754/Articles/index/1/whatever

我收到此错误

  

带有键&#39; Articles_Articles_Index_GET_xxx _&#39;的节点可能无法使用键标题添加路线值&#39;和价值的&#39; s&#39;到RouteValues字典,因为密钥是保留名称。保留名称是MvcSiteMapProvider内部使用的键,而不是字典值。

有效密钥可以是&#34; area&#34;,&#34; controller&#34;,&#34; action&#34;,以及与ISiteMapNode的属性名称不同的自定义参数。

您可以通过调用接受&#39; throwIfReservedKey&#39;的RouteValues.Add()或RouteValues.AddRange()的重载来抑制此错误消息。参数并为值传递false。请注意,如果您这样做,尝试将具有保留名称的密钥添加到RouteValues字典将无声地失败。

但如果我使用http://localhost:3333/Articles/index/1 要么 http://localhost:3333/Articles/index?id=1&&titile=ds

站点地图工作对我很好......

但我想从中使用  http://localhost:3754/Articles/index/1/whatever 在我的网站上。

感谢

1 个答案:

答案 0 :(得分:0)

我将标题名称更改为t(无论如何)。因为标题是站点地图中的键或保留,并与我的路线标题冲突,例如:url:“{controller} / {action} / {id} / {t}”,               默认值:new {controller =“Home”,action =“Index”,id = UrlParameter.Optional,t = UrlParameter.Optional}不要感谢我,谢天谢地

相关问题