0

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)
{
    ...
}
simoneL
  • 602
  • 1
  • 7
  • 23
  • It sounds like you really just want one action with multiple parameters. http://stackoverflow.com/questions/2246481/routing-with-multiple-parameters-using-asp-net-mvc – Daniel Sanchez Aug 19 '14 at 15:44
  • Can you be more precise? What do you expect from the URL above? Should the Release action be called with parameter 1, after that the Mildestone action with parameter 5 and last the Feature action with parameter 4? – WeSt Aug 19 '14 at 15:44
  • Yes, but I don't like the idea to use inexpressive url like BaseUrl/Release/1/5/4 – simoneL Aug 19 '14 at 15:45
  • Added additional information in the question about the expected behavior. – simoneL Aug 19 '14 at 15:48
  • use traditional query strings `BaseUrl/Milestone?releaseID=1&actionID=5&secondaryID=4` – Jonesopolis Aug 19 '14 at 15:53
  • @Jonesy I think get parameters are intended as optional. In my case all the IDs are mandatory. – simoneL Aug 19 '14 at 20:53

1 Answers1

1

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

Matias Cicero
  • 25,439
  • 13
  • 82
  • 154