我有以下控制器:
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
答案 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
);