One of the great features of ASP.NET MVC is the routing mechanism. I like to generate my URLs and not break anything when I change routes.
However, I am not sure how I can apply this mechanism on the client side.
Imagine a common scenario in which I have two drop-down lists, and the contents of the second list depend on the selected item in the first list. I want to load the elements of the second list asynchronously when the selection in the first list changes.
The URL using the default route might look like this: / Cars / GetModelsForBrand / Honda
Easy enough ...
var url = '/Cars/GetModelsForBrand/' + $("#brands").val();
What if I change the routing and the URL becomes: / Honda / GetModels
I just broke my code in an unobvious way.
Is there a way to generate URLs from the client side?
source
share