如何阻止URL.Action包含参数?

时间:2022-04-17 20:18:04

In my main navigation I have a link to:

在我的主导航中,我有一个链接:

Url.Action("Items", "FAQ");

Url.Action(“Items”,“FAQ”);

The link works fine and I get to ~/Item/FAQ

链接工作正常,我到〜/ Item / FAQ

However, I have links which contain parameters, so:

但是,我有包含参数的链接,所以:

~/Items/FAQ/Question-1

〜/项目/问题/问题-1

This all works fine, however, when I'm viewing Question-1 (which is a View, the link in the main navigation changes to:

这一切都很好,但是,当我查看问题1(这是一个视图,主导航中的链接更改为:

~/Items/FAQ/Question-1

〜/项目/问题/问题-1

How do I keep the Url in the navigation to stay at ~/Items/FAQ

如何将导航中的Url保留在〜/ Items / FAQ中

Thanks!

谢谢!

2 个解决方案

#1


8  

Url.Action("Items", "FAQ", new { WhateverYourRouteParameterIsCalled = "" })

#2


0  

I tried the answer but couldn't get it to work. In the end, I used a (comparatively) low tech solution:

我尝试了答案,但无法让它发挥作用。最后,我使用了(相对)低技术解决方案:

<a href="@Url.Content("~/Items/FAQ")">Nav Target Text</a>

This ignores any id values set by visiting that same page.

这会忽略通过访问同一页面设置的任何id值。

#1


8  

Url.Action("Items", "FAQ", new { WhateverYourRouteParameterIsCalled = "" })

#2


0  

I tried the answer but couldn't get it to work. In the end, I used a (comparatively) low tech solution:

我尝试了答案,但无法让它发挥作用。最后,我使用了(相对)低技术解决方案:

<a href="@Url.Content("~/Items/FAQ")">Nav Target Text</a>

This ignores any id values set by visiting that same page.

这会忽略通过访问同一页面设置的任何id值。