0

Is there a way to get an MVC route in Kentico to process multiple URL parameters within a single URL segment?

Example: I'm trying to route to /base/{param1}-{param2} I'd also like to be able to route to /base/{param1} Also, {param2} may contain one or more '-' characters... An example route would be: /base/1234-jon-doe-something-or-another This would ideally be fed into Kentico with param1 set to 1234 and param2 set to jon-doe-something-or-another

Is this possible?

The reason for the weird route is duplicating legacy functionality.

2
  • You're going to need two separate routes with constraints. base/{param1:int} and base/{param1:int}-{*param2}
    – Nkosi
    Sep 7, 2016 at 15:31
  • I had to use /base/{param} and separate the parameters in the consuming component. This works, with the caveat of requiring a one-off web part.
    – John URMC
    Sep 20, 2016 at 17:22

1 Answer 1

0
routes.MapRoute(
    name: "Your route",
    url: "/base/{param1}-{*param2}",
    defaults: new { controller = "Foo", action = "Index" }
);

Then in your FooController.cs

public ActionResult Index(string param1, string param2)
{
    // Do something with param1
    // Do something with param2
}

Now param2 will take everything after the first dash '-'.

You can keep structuring your url in the route if you want to add to the end of it, e.g. url: "/base/{param1}-{*param2}/more/routing",

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.