【发布时间】:2021-06-17 17:24:17
【问题描述】:
我正在研究 RAZOR。
_layout.cshtml 包含以下内容作为侧边栏
<a class="sidebar-brand" href="../Purchase/Index">
它打开 https://localhost/Purchase/Index
它适用于任何 CSHTML 页面。但是,如果我点击编辑页面,我可以看到上面的 URL
https://localhost/Purchase/Edit/46
从这个页面,如果我点击购买链接,那么它会尝试打开
https://localhost/Purchase/Purchase/Index
而不是
https://localhost/Purchase/Index
显然,../Procurment/Index 在这种情况下不起作用。
如何在 href 中处理这个问题?
【问题讨论】:
-
当您使用“../Purchase/Index”等相关路径时,它将附加到
routes.MapRoute()调用生成的路由中。因此,您将获得https://localhost/Purchase/Purchase/IndexURL。 -
如果需要参考
Purchase控制器的Index动作方法使用href="/Purchase/Index"。这与href="~/Purchase/Index"相同。 -
非常感谢 Jacdaw。我没有意识到这一点。 ~ 作品
标签: html asp.net asp.net-mvc razor