Asp.net mvc 4 MVC4中的正确路由模式

Asp.net mvc 4 MVC4中的正确路由模式,asp.net-mvc-4,routes,maproute,Asp.net Mvc 4,Routes,Maproute,我在www.server.com/events/calendar上有日历。我的事件查询字符串类似于www.server.com/events/calendar/seofriendy-event-query-string。但用户可以使用下拉列表按年度和月份选择事件,因此mu查询变成了www.server.com/events/calendar/2013,甚至变成了www.server.com/events/calendar/2013/12。所以问题是,当我单击www.server.com/even

我在www.server.com/events/calendar上有日历。我的事件查询字符串类似于www.server.com/events/calendar/seofriendy-event-query-string。但用户可以使用下拉列表按年度和月份选择事件,因此mu查询变成了www.server.com/events/calendar/2013,甚至变成了www.server.com/events/calendar/2013/12。所以问题是,当我单击www.server.com/events/calendar/seofriendy-event-query-string时,我得到了www.server.com/events/calendar。如何安排我的路线,使他们了解我需要显示的内容:列表还是事件?

好吧,我会添加一个自定义路线,如下所示:

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
        }
 }
然后,控制器将具有如下操作方法:

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
        }
 }
您只需要接收参数并运行某种检查,以确定是否要显示事件或列表