In a URL like http://mysite.com/controller/action/123/name-of-article, is there a way to define the route so that the '123/name-of-article' part is passed in as a string?
2 Answers
I am not sure what your requirements are, but are you sure you want to pass the name of the article to the controller? Would you be better off just passing the ID then doing a SELECT from the database to get the Name?
If you still wanted to have a URL like http://mysite.com/controller/action/123/name-of-article
but only pass in the ID you can use a route like this
routes.MapRoute(
"MyNewRoute", // Route name
"articles/edit/{id}/{name}", // URL
new { controller = "Articles", action = "Edit", id = "" }, // Defaults
new[] { "YourApp.UI.Controllers" } // Namespaces
);
Then your controller action
public ActionResult Edit(int id)
{
}