我的VisitsController:
public ActionResult Index(Visits visits, int? id)
{
....
return View(v);
}
这是我的路线配置
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index",
id = UrlParameter.Optional }
);
}
Works: http://localhost:49225/Visits
Does not work: http://localhost:49225/Visits/123
自定义路由是什么(并强制它为整数)?
答案 0 :(得分:1)
您需要添加新的路线才能发挥作用。
目前,这将有效:
/Visits/Index/123
我相信你需要添加以下内容:
routes.MapRoute(
name: "VisitsDefault",
url: "Visits/{id}",
defaults: new { controller = "Visits", action = "Index",
id = UrlParameter.Optional }
);
假设您已经有Visits的模型绑定器。