Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/266.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# MVC5路线不';行不通_C#_Asp.net Mvc - Fatal编程技术网

C# MVC5路线不';行不通

C# MVC5路线不';行不通,c#,asp.net-mvc,C#,Asp.net Mvc,我最近从MVC5升级到MVC3。我从未注册过路由,但是,此URL有效: 这是我的密码: [HttpPost] public ActionResult Index(string id, string website) { string data = string.Empty; } 我现在得到一个404和这个代码。我尝试了这条路线,但也失败了: public static void RegisterRoutes(RouteColle

我最近从MVC5升级到MVC3。我从未注册过路由,但是,此URL有效:

这是我的密码:

    [HttpPost]
    public ActionResult Index(string id, string website)
    {
        string data = string.Empty;
    }
我现在得到一个404和这个代码。我尝试了这条路线,但也失败了:

        public static void RegisterRoutes(RouteCollection routes)
        {
           routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
"ShipWorks", // Route name
"{controller}/{action}/{id}/{website}", // URL with parameters
new { controller = "ShipWorks", action = "Index", email = UrlParameter.Optional, website =     
UrlParameter.Optional }, new[] { "CloudCartConnector.Web.Controllers" }// Parameter defaults
);

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
}

我做错了什么?我将运输路线置于默认路线之上。请注意,我的id是一个字符串。URL与?id配合使用效果良好=myemail@myemail.com.第一种方法。


根据您的路径:

"{controller}/{action}/{id}/{website}"
您不需要明确指定“网站”属性名。然后,您在路由中标记了
{id}
{website}
用斜线分隔,因此正确使用路由掩码应该是
http://www.testsite.com/shipworks/index/myemail@yahoo.com/testsite.com

但是,这里有一个问题-点符号
将无法正确识别(以您希望的方式)。因此,如果删除点,路径
http://www.testsite.com/shipworks/index/myemail@yahoo.com/testsitecom
将起作用

第二种方法。
为了获得想要的结果,最好将电子邮件和网站作为查询参数传递,而不是作为路径的一部分传递。
您可以使用以下路由配置:

routes.MapRoute(
    "ShipWorks", // Route name
    "{controller}/{action}/{id}", // URL with parameters
    new
    {
        controller = "ShipWorks",
        action = "Index",
        id = UrlParameter.Optional
    }, new[] { "CloudCartConnector.Web.Controllers" }// Parameter defaults
);
控制员的行动:

//[HttpPost]
public ActionResult Index(string email, string website)
{
    (...)
    return View();
}
和查询字符串:
http://www.testsite.com/shipworks/index?email=myemail@yahoo.com&website=testsite.com


还请注意,由于您使用
[HttpPost]
属性标记了
索引
方法,因此即使您有正确的URL,您也将使用
get
方法(如在浏览器中键入)获得
404

如果路由似乎不起作用,您需要按照添加路线的顺序列出所有路线。
shipping/index/{id}
将不起作用,因为URL中没有“索引”。请尝试
shipping/{id}
,谢谢。我尝试了索引并列出了路线。我仍然看到404。第二次进近的路径上仍然有点,现在没事了