Reputation: 5632
I'm trying to learn asp.net mvc, and almost everywhere I see route description with three components like /Controller/Action/{anyParams} I'd like to know if I can map a route similar to,
/Folder(or namespace)/Controller/Action/params...
ex:
/Admin/Student/Edit/id /ABC/Faculty/Add/` /XYZ/Student/Edit/id
or in general,
/XYZ/Controller1/Action/{param}
Upvotes: 0
Views: 252
Reputation: 27352
You can make your routes as complex as you want.
F.e. the following route:
routes.MapRoute("some-route", "products/detail/order/{id}/{name}/",
new { controller = "Products", action = "Order" },
new { id = "^\d+" });
will route to the following function:
public class ProductsController : Controller {
public ActionResult Order (int id, string name) {
}
}
So you can specify as many parameters as you want, and they will be passed into your action as function parameters.
Upvotes: 1
Reputation: 26
Yep the second parameter in the MapRoutes function (usually in Global.asax.cs is Url and this can be any pattern you want. something like
routes.MapRoute("MyRoute", "XYZ/Controller1/Action/{param}",
new {controller = "Controller1", action = "Action"}});
should do the trick.
Upvotes: 1