简体   繁体   English

如何在asp.net MVC4中使用路由?

[英]how can i use routing in asp.net MVC4?

i have one problem arrive in my application actually my application is has some functionality like as searching...etc When you search with like computer keyword then url is like as below 我在我的应用程序中遇到一个问题,实际上我的应用程序具有某些功能,例如search ... etc。当您使用类似计算机的关键词进行搜索时,URL如下所示

http://www.example.com/Computer-Company/computer/1 http://www.example.com/Computer-Company/computer/1

Here computer is keyword But Company is my controller name so i write down some code in my RouteConfig.cs file the code is 这里的计算机是关键字,但是Company是我的控制器名称,所以我在RouteConfig.cs文件中写下了一些代码,代码是

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

and i have also header and header contain some links like as Home when i hover on the home link at that time my url is below 而且我还有标头,并且标头包含一些链接,例如Home,当我将光标悬停在主页链接上时,我的网址在下面

http://www.example.com/-Home http://www.example.com/-Home

so please how can i solve it. 所以,我该怎么解决。

If you use page parameter with *, you can send to action. 如果将页面参数与*一起使用,则可以发送至操作。

routes.MapRoute(
  "SearchResult",
  "Company/{*page}",
  new { controller = "Company", action = "Index" }

); );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM