0

The index function in the controller takes three parameters let's say 'a', 'b', 'c'. Currently i am able to pass values to those parameters in the url like action?a="1"&'b'=2&'c'=3.

I would like to send value to param 'b' in the url in the form action/"value" or action/b="value". I tried editing the routing in Global.asax.cs but i am getting the error "Controller for the path was not found or does not implement iController". Any help on this issue would be greatly appreciated

1 Answer 1

1

You should build this into your route tables in the global.asax in this manner:

RouteTable.Routes.Add(new Route
{
    Url = "[controller]/[action]/[a]/[b]/[c]",
    Defaults = new { controller = "myController", action = "myAction", a = "1", b = "2", c = "3" },
    RouteHandler(typeof(MvcRouteHandler)
});

To break it down, the Url parameter shows the structure of the expected Url, the defaults parameter provides default values for any of these that may be empty. Keep in mind that this will always expect a route of myDomain.com/myController/myAction/1/2/3 or something that matches the structure like myDomain.com/myController/myAction///. If you need to have differing subsets of these values, you will need to adjust your routes accordingly. Also, you'll need to make sure that this route appears fairly early in your route definitions. The routes are determined by the first matching route that it finds, so the more complex (harder to reach) routes should always be early to allow default routes to catch anything that misses.

Reference: http://weblogs.asp.net/scottgu/archive/2007/12/03/asp-net-mvc-framework-part-2-url-routing.aspx

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

1 Comment

The current project that i am working on uses MapRoutes. I tried to map the route in the below given way: context.MapRoute("route", "controller/action/{a}", new { controller = "sampleController", action = "sampleaction", a = "" });

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.