I am using .net MVC in my website and I need to get the URL in javascript, but only the controller and action name, for instance if i have:
http://stackoverflow.com/questions/9513736/current-url-without-parameters-hash-https
I need:
http://stackoverflow.com/questions/9513736/
I have found some solutions such as:
urlBase = location.href.substring(0, location.href.lastIndexOf("/")+1)
->http://stackoverflow.com/questions/9513736/
However if my URL does not have any parameters I the action name is cut off like so:
http://stackoverflow.com/questions/
Does anyone have a solution for this?
/if it does then don't substring it. That might work for you. Personally I would look to see if you can access the controller and action names through razor and write it directly to the javascript so you don't have to parse it.