Ber53rker
Ber53rker

Reputation: 649

Return MVC final current path in JQuery?

Right now I'm using...

window.location.pathname != "/x_Controller/x_View"

Is there any way to get just the "x_View"? Thanks.

Upvotes: 1

Views: 1368

Answers (1)

Rondel
Rondel

Reputation: 4951

You can just do a substring of the window.location.pathname

var pathname= window.location.pathname;
var endURL= pathname.substring(pathname.lastIndexOf('/') + 1,pathname.length);

EDIT

As Galactic suggested this won't get you the action name if it has any route values on the end like actionName/12. What you really want to use is

var [email protected]("action").RawValue;

That will get you the actual name of the Action instead of just the stuff after the last '/'

Upvotes: 2

Related Questions