我在 www.server.com/events/calendar 有一个日历。我的事件查询字符串看起来像 www.server.com/events/calendar/seofriendly-event-query-string。但是用户可以使用下拉列表按年份和月份选择事件,因此 mu 查询变为 www.server.com/events/calendar/2013 甚至 www.server.com/events/calendar/2013/12。所以问题是当我点击 www.server.com/events/calendar/seofriendly-event-query-string 我得到 www.server.com/events/calendar。如何安排我的路线,让他们了解我需要展示的内容:列表还是事件?
问问题
73 次
1 回答
1
好吧,我会添加这样的自定义路线:
routes.MapRoute(
"NewRoute", // Route name
"{controller}/{action}/{id}/{another_id}", // URL with parameters
new { controller = "Events", action = "Calendar", id = UrlParameter.Optional, another_id = UrlParameter.Optional } // Parameter defaults
);
然后,您的控制器将具有如下操作方法:
public ActionResult MyAction(string id, string another_id)
{
// in the question you mentioned that a a valid list querystring would contain
// multiple integer parameters, and an event querystring would include a
//seo friendly string
int para;
if (int.TryParse(id,out para))
{
// show list view
}
else
{
//show event view
}
}
您只需要接收参数并运行某种检查以确定您是要显示事件还是列表。
于 2013-12-09T15:48:08.873 回答