I would like my MVC Urls to be like so:
http://www.site.com/project/id/projectname
Example:
http://www.site.com/project/5/new-website
My controller is:
public ActionResult Details(int id, string projectname)
Any my actionlink is:
@Html.ActionLink("click here", "Details", "Project", new { id = project.ProjectID, projectname = project.ProjectName })
And my route is:
routes.MapRoute(
"Project",
"project/{id}/{projectname}",
new { controller = "Project", action = "Details", id = "", projectname = "" }
);
Surely the system has enough information there, to know that project name will be part of the Url, so it should UrlEncode the link and thus replace spaces with hyphens? But it doesn't, and so spaces become %20
I'm not sure where I customise this? Do I override the Html.ActionLink? Storing a "URL-ready" version of the name in the database on every edit - seems like a such a waste, when it should be done automatically, on the fly. And I don't want to have to call a "FriendlyURL" function every time I use an Html.ActionLink - again, it should be dealt with automatically.