In the ASP.MVC I am developing I neet to have more than one action in the url.
This is an example
BaseUrl/Release/1/Milestone/5/Feature/4
How can i configure the routes and the action methods to achieve this?
In this case I expected the action Milestone in the ReleaseController is the one that get called, with three input id:
public class ReleaseController : Controller
{
public ActionResult Milestone(int releaseID, int actionID, int secondaryID)
{
...
}
}
EDIT: Thank you @Mati Cicero to pointing me to the right direction. I followed his solution making also url a little more "dynamic". This is my final code, maybe can be useful also for someone else:
routes.MapRoute(
name: "ReleaseSection",
url: "Release/{releaseId}/{action}/{actionID}/{subAction}/{thirdID}",
defaults: new
{
controller = "Release",
action = "Index",
releaseId = UrlParameter.Optional,
actionID = UrlParameter.Optional,
subAction = UrlParameter.Optional,
thirdID = UrlParameter.Optional
}
);
public ActionResult Milestone(int? releaseId, int? actionID, string subAction, int? thirdID)
{
...
}
I did not test this, but did you try the following route?
Url : BaseUrl/Release/{releaseID}/Milestone/{actionID}/Feature/{secondaryID}
Defaults : new { controller = "Release", action = "Milestone" }
Constraints : new { releaseID = "\\\\d+", actionID = "\\\\d+", secondaryID = "\\\\d+" }
The MVC engine should map the route segments to you action's arguments
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.