我定义了以下路由:
routes.MapRoute(
"EventInfo", // Route name
"Events/{year}/{month}/{day}", // URL with parameters
new { controller = "Events", action = "Index", year = UrlParameter.Optional, month = UrlParameter.Optional, day = UrlParameter.Optional } // Parameter defaults
);
routes.MapRoute(
"EventType", // Route name
"Events/Type/{id}/{year}/{month}/{day}", // URL with parameters
new { controller = "Events", action = "Type", id = UrlParameter.Optional, year = UrlParameter.Optional, month = UrlParameter.Optional, day = UrlParameter.Optional } // Parameter defaults
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);我在导航时看到一些“奇怪”的行为。例如,我在主菜单上有一个Html.ActionLink,它的定义如下:
<li class="@item.Class">@Html.ActionLink(item.Title, item.Action, item.Controller, null, new { @class="standard" } )</li>我也有一个侧边栏的二级菜单定义在我的视图相同的方式-我只是改变了什么模型提供两个不同的(部分)视图。例如,我的主菜单的Model如下所示:
public MenuItems()
{
List = new List<Menu> {
new Menu { Controller="Home", Action="Index", Title="Home", Class="grid-2 menubutton" },
new Menu { Controller="Info", Action="Index", Title="Information", Class="grid-2 menubutton" },
new Menu { Controller="Events", Action="Index", Title="Events", Class="grid-2 menubutton" },
new Menu { Controller="Guilds", Action="Index", Title="Guilds", Class="grid-2 menubutton" },
new Menu { Controller="Populace", Action="Index", Title="Caer Galenites", Class="grid-3 menubutton" },
new Menu { Controller="Loop", Action="Index", Title="Get in the Loop", Class="grid-3 menubutton" }
};
}现在,我正在测试我的事件页面(参见上面的路线),所以一旦我进入主事件页面,我就会修改URL。例如:我点击主菜单中的事件,进入http://site.com/Events,我看到了我的事件列表。然后,我像http://site.com/Events/2011一样追加一个年份,过滤器就可以工作了。追加一个月份,比如http://site.com/Events/2011/9,现在我可以看到当前月份的事件。到现在为止还好。
然后,我将鼠标悬停在侧边栏的一个菜单项上,希望看到的是http://site.com/Events/Type/Kingdom,但看到的却是http://site.com/Events/Type/Kingdom/2011/9。我将鼠标悬停在主菜单链接上,看到的不是http://site.com/Events,而是http://site.com/Events/2011/9。如果我将鼠标悬停在其他主菜单项上,它们会显示正确的URL。
为什么?我如何“修复它”?
提亚
发布于 2013-01-30 06:48:54
按照上面评论中的建议,我让它都正常工作了。我没有将日期部分作为URL (yyy/mm/dd)的一部分,而是选择了单个日期字符串( yyyy-mm -dd或yyyy-mm或yyyy),并使用解析器将其拆分开来,然后返回正确的清单。
https://stackoverflow.com/questions/7504425
复制相似问题