C# MVC3中的RedirectToAction返回“;路由表中没有与提供的值匹配的路由;
我使用此登录控制器:C# MVC3中的RedirectToAction返回“;路由表中没有与提供的值匹配的路由;,c#,asp.net-mvc,asp.net-mvc-3,asp.net-mvc-4,razor,C#,Asp.net Mvc,Asp.net Mvc 3,Asp.net Mvc 4,Razor,我使用此登录控制器: public ActionResult Index(LoginModel model) { if (model.usernam == "usernam" && model.password == "password") { return RedirectToAction("Index", "Home"); } return V
public ActionResult Index(LoginModel model)
{
if (model.usernam == "usernam" && model.password == "password")
{
return RedirectToAction("Index", "Home");
}
return View();
}
此RedirectToAction返回此异常:路由表中没有与提供的值匹配的路由。
在我的Globa.asax中,我有这个值,我认为它可以解决这个问题,但我不知道如何解决
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}/{id1}/", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional, id1= UrlParameter.Optional} // Parameter defaults
);
}
我在网上搜索了一下,找到了很多建议,但都不管用。
有什么解决办法吗
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}/{id1}/", // URL with parameters
new { controller = "Home",
action = "Index",
id = UrlParameter.Optional,
id1 = UrlParameter.Optional
} // Parameter defaults
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}", // URL with parameters
new { controller = "Home", action = "Index" } // Parameter defaults
);
}
如果注意上面的代码,您将丢失没有参数的默认路线。您不能有两个可选参数。请参见,不能有两个同名的路由“Default”。