Published on

ASP.Net MVC and URLs ending in a decimal or float

Authors
  • avatar
    Name
    Mike Barram
    Twitter

In your MVC site, you might want this URL to purchase 2.5 kilos of cheese for you
https://www.mysite.com/cheese/purchase/2.5
Unfortunately it won’t be recognised as a route to the purchase method within the cheese controller. The good news is that this will work:
https://www.mysite.com/cheese/purchase/2.5/ Note the extra slash at the end

This is an explanation why:
http://stackoverflow.com/questions/21387974/why-is-my-web-api-method-with-double-args-not-getting-called

It’s fairly unusual to have a valid reason for a URL like this. If you want to pass a parameter that’s a float, it’s more likely that you would want to post the data.