Calling method in MapRoute MVC

521 views Asked by At

Is it possible to pass a parameter from "url" section to a method in "default" section of MapRoute?

routes.MapRoute(
               name: "Language",
               url: "{language}/{controller}/{action}/{id}-{description}",
               defaults: new { Controller = "Home", action = "Index", id = UrlParameter.Optional, language = UrlParameter.Optional, description = GetDescription(id) }
           );

I am able to call GetDescription() without any parameters but I dont know how to pass a parameter from url ie. GetDescription(id)?

1

There are 1 answers

3
Marian Ban On BEST ANSWER

I think that you have misunderstood the concept of route definition. You cannot add dynamic behavior into rote registration process because it is executed only once on application start event. The defaults parameter is used when the routing engine does not find a appropriate parameter in the provided URL. What are you trying to do is possible on url generation level:

@Html.ActionLink("Home", "Index", new { language = "en", id=5, description = "test" })