Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.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# 改进asp.net mvc2中的URL_C#_Asp.net Mvc_Visual Studio 2010_Asp.net Mvc 2 - Fatal编程技术网

C# 改进asp.net mvc2中的URL

C# 改进asp.net mvc2中的URL,c#,asp.net-mvc,visual-studio-2010,asp.net-mvc-2,C#,Asp.net Mvc,Visual Studio 2010,Asp.net Mvc 2,改进URL 目前我在表单中有链接(显示产品信息): 我想把它整理成以下表格: 我想我需要使用路由。MapRoute,类似这样: routes.MapRoute(null, "/Products/Page{page}", new {controller = "ProductController", action = "Index"}); 这是放在默认路线之上的(因此应该覆盖我被引导相信的路线) 产品控制器如下所示: // // GET: /Products/ publ

改进URL

目前我在表单中有链接(显示产品信息):

我想把它整理成以下表格:

我想我需要使用
路由。MapRoute
,类似这样:

routes.MapRoute(null, "/Products/Page{page}", new {controller = "ProductController", action = "Index"});
这是放在默认路线之上的(因此应该覆盖我被引导相信的路线)

产品控制器如下所示:

    //
    // GET: /Products/
    public ActionResult Index([DefaultValue(1)] int page)
    {
        var productsToShow = //omitted for simplicity

        var viewModel = new ProductIndexViewModel
                            {
                                ProductList = //omitted for simplicity,
                                PagingInfo = new PagingInfo
                                                 {
                                                     CurrentPage = page,
                                                     ItemsPerPage = PageSize,
                                                     TotalItems = productsToShow.Count()
                                                 }
                            };

        //Passed to view as ViewData.Model (or simply Model)
        return View(viewModel);
    }

我做错了什么?

更改
routes.MapRoute

routes.MapRoute(null, "Products/Page{page}", new {controller = "Products", action = "Index"});
正确-惯例是所有控制器类都以单词
controller
结尾。因此,路由不需要您在路由详细信息中添加完整的单词,如上所述。正如@Akyegane所说,controller=“Products”。。不是“产品控制器”