动态获取 ASP.NET MVC 的路径名

发布于 2024-08-30 18:31:33 字数 299 浏览 1 评论 0原文

我正在寻找一种解决方案,允许我从调用的partialView 获取父页面路径名。例如,我有一个 Action baa 和一个控制器 boo,因此获取它的 javascript 将是 window.location.pathname,并且它返回 /boo/baa。

问题是我使用了部分视图,因此当我尝试通过 URL 帮助程序检索路径名时,我获得的是 PartialView 视图,而我需要的是调用它的操作的路径名。我想这样做是因为我想根据调用它的父视图的路径名来显示分部视图的某些内容。有没有办法用 ASP.NET MVC 来做到这一点?

预先感谢大家,

I'm looking for a solution that allows me to get the parent page pathname from a partialView invoked. For example I have an Action baa and a controller boo so the javascript to obtain this will be window.location.pathname, and it returns /boo/baa.

The thing is that I use a partial view, so when I try to retrieve the pathname via the URL helper, what I obtain is the PartialView one, and what I need is the pathname for the action that invokes it. I want to do this because I want to show certain things of the partial view depending on the pathname of the parent view that invokes it. Is there a way to do this with ASP.NET MVC?

Thank you all in advance,

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

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

发布评论

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

评论(1

霞映澄塘 2024-09-06 18:31:33

您可以在页面的ViewContext上访问RouteValues。这将包含由路由引擎确定的控制器和操作值。然而,您可能需要考虑将确定信息作为模型的一部分,因为这会公开控制器中的逻辑——不过,视图如何处理这些信息完全取决于它。

You can access the RouteValues on the ViewContext on the page. This will contain the controller and action values as determined by the routing engine. You might want to consider making the determining information part of your model, however, as this exposes logic in the controller -- what the view does with this information, though, is completely up to it.

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