Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.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
Asp.net mvc 如何知道MVC.NET试图查找的URL_Asp.net Mvc_Asp.net Mvc 4 - Fatal编程技术网

Asp.net mvc 如何知道MVC.NET试图查找的URL

Asp.net mvc 如何知道MVC.NET试图查找的URL,asp.net-mvc,asp.net-mvc-4,Asp.net Mvc,Asp.net Mvc 4,我的MVC4应用程序有一个表单。在这种情况下,人们从选择框中选择条件,然后单击搜索 此时,它指向控制器,控制器将该值存储为TempData,然后重定向到正确的登录页 因此,从视图中,单击搜索按钮后,路径是my ProductController中的Shoes [HttpGet] public ActionResult Shoes(Shoe shoe) { TempData["shoe"] = shoe; return RedirectT

我的MVC4应用程序有一个表单。在这种情况下,人们从选择框中选择条件,然后单击搜索

此时,它指向控制器,控制器将该值存储为
TempData
,然后重定向到正确的登录页

因此,从视图中,单击搜索按钮后,路径是my ProductController中的Shoes

    [HttpGet]
    public ActionResult Shoes(Shoe shoe)
    {

        TempData["shoe"] = shoe;

        return RedirectToAction("Index", "Shoes", new  { SelectedSize = shoe.SelectedSize, SelectedColour = shoe.SelectedColour });

    }
以上内容重定向到

    [HttpGet]
    public ActionResult Index(Shoes shoes, int startIndex, int pageSize)
    {
        //logic
    }
我的两条路线是

   routes.MapRoute(
      name: "ShoesA",
      url: "Shoes/{startIndex}",
      defaults: new { startIndex = 0, pageSize = 10, controller = "ShoesConnectors", action = "Index" }
      );

        routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}",
        defaults: new { controller = "Home", action = "Index" }
        );
一切正常。URL解析为
http://localhost:52603/Shoes?SelectedSize=12

我想要的是将URL更改为不使用querystring。乙二醇

http://localhost:52603/Shoes?SelectedSize=12

成为

http://localhost:52603/Shoes/12

(我应该指出,我通过路由使用分页,因此它实际上会显示
http://localhost:52603/Shoes/10/12
其中
10
是起始索引)

因此,我添加了以下路线

        routes.MapRoute(
        name: "ShoesB",
        url: "Shoes/{startIndex}/{SelectedSize}/{SelectedColour}",
        defaults: new { startIndex = 0, pageSize = 10, controller = "Shoes", action = "Index" }
        );

        routes.MapRoute(
        name: "ShoesC",
        url: "Shoes/{startIndex}/{SelectedSize}",
        defaults: new { startIndex = 0, pageSize = 10, controller = "Shoes", action = "Index" }
        );

        routes.MapRoute(
        name: "ShoesD",
        url: "Shoes/{startIndex}/{SelectedColour}",
        defaults: new { startIndex = 0, pageSize = 10, controller = "Shoes", action = "Index" }
        );
当我点击我的搜索按钮时,我会看到一个404页面

我知道这个错误是由于新的路由而存在的,但我不明白为什么它找不到页面

URL按预期解析为
http://localhost:52603/Shoes/0/12
但是,我不知道如何调试它

为什么MVC找不到正确的控制器?它试图解决什么问题?

您想使用


编辑:顺便说一句,如果您要更新到
MVC5
,属性路由是“内置的”(请参阅)

答案是,这在MVC4中很容易完成。我发布的示例非常正确

错误在Visual Studio项目中的设置范围内。我打开了项目的属性,并导航到Web选项卡

从这里,我取消选中“使用本地IIS Web服务器”,并选择“使用Visual Studio开发服务器”,这就解决了问题