views:

22

answers:

2

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.

+2  A: 

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.

Dan Dumitru
but the problem is i am having another url like '/builgingproject' which should map to default but on putting custon routes above default one this url is mapped to this custom route.And this showing error.
andrew Sullivan
@Andrew - show us both your URLs, how they look like. Not the code in the view, but exactly how they look rendered in your page, and we'll try to help. (you can edit your question with this info)
Dan Dumitru
Firts Url is "/BuildingProject"(this should map to default on) and second one is "BuildingCompany/{projectId}/BuildingProject"(this should map to custom one".
andrew Sullivan
A: 

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

Ahmad