Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MVC3中的RedirectToAction返回“;路由表中没有与提供的值匹配的路由;_C#_Asp.net Mvc_Asp.net Mvc 3_Asp.net Mvc 4_Razor - Fatal编程技术网

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”。