返回 JQuery 中 MVC 最终当前路径?

发布于 2024-12-22 03:31:24 字数 126 浏览 2 评论 0原文

现在我正在使用...

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

有什么方法可以只获取“x_View”吗?谢谢。

Right now I'm using...

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

御守 2024-12-29 03:31:24

您只需执行 window.location.pathname

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

EDIT

的子字符串,正如银河建议的那样,如果它末尾有任何路由值,则不会为您提供操作名称actionName/12。您真正想要使用的是,

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

这将为您提供操作的实际名称,而不仅仅是最后一个“/”之后的内容

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 '/'

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文