开发者

problem in routing in asp.net mvc

i have

 routes.MapRoute("BuildingCompanyProject", "BuildingCompany/{projectId}/BuildingProject", new { controller = "BuildingProject", action = "Index", projectId = "" });

in Global.asax.cs

and is placed below the default route.

and the above route is called on clicking a link

<a title="Go toCompany" style="background: none!important" href='<%= Url.RouteUrl("BuildingCompanyProject",new {controller="BuildingProject" , action="Index" , projectId=item.Id})%>'>
               开发者_运维百科 beheer bedrijf</a>   

But on clicking the url is mapped to default route. How should i achieve this.


You should put custom routes above the default route, when the default route could resolve your custom route (like it is in your case).


In light of your comment, you say you have another URL "/BuildingProject" that should be resolved by the default route.

You should have then 3 routes: first the one to resolve "/BuildingProject", then your custom one that you talked about in the question, and only in the end the default route.


Move your custom route above the default route. Remember that your url will match the default route first

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜