I have a DirectoryController with an Index() ViewResult which displays the following links in the view:
@Html.ActionLink("My file 1", "Index", "File", new { @id = "123" }, null) <br />
@Html.ActionLink("My file 2", "Index", "File", new { @id = "456" }, null) <br />
@Html.ActionLink("My file 3", "Index", "File", new { @id = "789" }, null) <br />
If I click on one of the links, I’ll end up having (for example) the following in the URL:
What I’d really like to have is the following in the URL:
Basically, I’d like to see the Controller name and a custom name (the name of the file for example) in the URL without showing the actual action or the id.
Regardless of the link I click, all of them should continue to point to the Index() method of the FileController passing along the appropriate id.
How would I go about this?
How and what kind of custom route should I create?
Thanks
%. Though they will get converted in your URL, unlike QueryString paramters, they will crash the call as they can't be parsed by the routing. For more details on that particular issue see my answer as well as another post I linked there in this post here: stackoverflow.com/questions/9123203/…