0

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 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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 - 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)
Firts Url is "/BuildingProject"(this should map to default on) and second one is "BuildingCompany/{projectId}/BuildingProject"(this should map to custom one".
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.