在asp.net mvc2中传递参数时出现问题

时间:2010-04-02 05:49:35

标签: asp.net-mvc parameters controllers

我有以下控制器:

public ActionResult Search(string Name,int?Friend,int?Page)

如果我使用此url localhost / users / search / name但这些不是localhost / users / search / name / 1和localhost / users / search / name / 1/1

1 个答案:

答案 0 :(得分:3)

您必须定义其他路线:

routes.MapRoute(
                "UsersSearch",                                              // Route name
                "users/search/{name}/{friend}/{page}",                           // URL with parameters
                new { controller = "Users", action = "Search" }  // Parameter defaults
            );


routes.MapRoute(
                "UsersSearch",                                              // Route name
                "users/search/{name}/{friend}",                           // URL with parameters
                new { controller = "Users", action = "Search" }  // Parameter defaults
            );