In a C# MVC4 web project I have the following custom route:
routes.MapRoute(
name: "ProductDetails",
url: "Details/{productName}/{revision}",
defaults: new { controller = "Product", action = "Details", productName = "", revision = 1 });
Which points to a controller method:
public ActionResult Details(String productName, Int32? revision)
{ ... }
And I generate links like this:
<a href="@Url.Action("Details" ,"Product", new { productName = @prod.ProductName, revision = @prod.Revision })" ...
When my product name contains slashes, in the html source I see it is url encoded (sometimes, sometimes not). When I urlencoded the product name, the MVC says it is double-encoded and so it fails. When I not - sometimes it is not encoded like this time:
<a href="/Products/Details/green/banana/apple" title="View detail">View</a>
I cannot use product ID here, must use the name. The name may contains slashes and other special characters. They are requirements.
How should I handle this situation on code side? How to configure the route itself, or use some custom encoding-decoding step?
Thanks for your kind advice!