ASP MVC encoding route values
I’ve recently been using ASP MVC 2 to develop a business application. As you may already know the ASP MVC routing system works with URLs which look like this http://localhost/Client/Details/IBM In standard ASPX apps the URL would look more like this http://localhost/Client/Details.aspx?code=IBM The first URL obviously looks much nicer than the 2nd, however it comes at a cost. What if the “code” of your object is something like “N/A” for “Not applicable”? You end up with a URL that looks like this http://localhost/AbsenceCode/Details/N/A What we really need is to have ASP MVC encode the value “N/A” as “N%2FA”. The problem is that even if it did do this then by the time ASP MVC receives the value it has already been decoded, so we get a “400 bad request” error. This is a real pain, because in business we can’t really tell a customer “You can only use characters A to Z, 0 to 9, underscore and minus in your codes” because they will tell you that they have used the code N/A