MVC URL路由无法正常工作

时间:2022-06-18 11:21:20

This is my Global.asax , all I want to map another url format to controller and action.

这是我的Global.asax,我想将另一个url格式映射到控制器和动作。

        //Matching to auctions-index-Testing
        //Why this one is not matching to auction-index
        routes.MapRoute("TestUrl", "{controller}-{action}-{name}",
            new { name = UrlParameter.Optional }
            );


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

I am wondering why auction-index is giving me "Resource not found error". Name is optional and it is first entry in table. so it should be matched with the URL

我想知道为什么拍卖索引给我“资源未找到错误”。名称是可选的,它是表格中的第一个条目。所以它应该与URL匹配

any help and suggestion would be grateful

任何帮助和建议将不胜感激

1 个解决方案

#1


1  

Try this instead ::

试试这个::

routes.MapRoute("TestUrl", "{controller}-{action}-{name}",
    new { controller = "auctions", 
          action = "index", 
          name = UrlParameter.Optional }
);

Hope this will help !!

希望这会有所帮助!!

#1


1  

Try this instead ::

试试这个::

routes.MapRoute("TestUrl", "{controller}-{action}-{name}",
    new { controller = "auctions", 
          action = "index", 
          name = UrlParameter.Optional }
);

Hope this will help !!

希望这会有所帮助!!