Reputation: 1
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
Upvotes: 0
Views: 75
Reputation: 37523
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
Upvotes: 1