Html.ActionLink错误地拿起当前RouteValues [英] Html.ActionLink erroneously picks up the current RouteValues
问题描述
所以我有一个路径(例如〜/帮助/ FAQ)。现在,如果我比其他常见问题解答任何页面上, Html.ActionLink
工程,我期望的那样。
So I have a Route (e.g. ~/Help/FAQ). Now, if I am on any page other than the FAQ, Html.ActionLink
works as I would expect.
@Html.ActionLink("FAQ", "FAQ", "Help", routeValues:=Nothing, htmlAttributes:=Nothing)
但是,如果当前的浏览器URL是FAQ页面的与指定的ID路由属性的 http://www.example.com/Help/FAQ/56832
,那么ActionLink的上述拿起当前routeVaues并呈现与 56832
附链接 - 尽管我特别告诉ActionLink的,我不希望任何routeValues被渲染。
But if the current browser URL is the FAQ page with the id route attribute specified, http://www.example.com/Help/FAQ/56832
, then the ActionLink above picks up the current routeVaues and renders the link with the 56832
attached - even though I am specifically telling the ActionLink that I do not want any routeValues to be rendered.
这是一个错误还是我做错了什么?
Is this a bug or am I doing something wrong?
推荐答案
您没有做错什么,ASP.NET MVC隐含使用HTML佣工当前路由值。你将不得不覆盖它们:
You are not doing anything wrong, ASP.NET MVC implicitly uses the current route values in HTML helpers. You will have to overwrite them:
在C#中:
@Html.ActionLink("FAQ", "FAQ", "Help", new { id = null }, null)
在VB.NET:
@Html.ActionLink("FAQ", "FAQ", Help", routeValues:= New With {.id = Nothing}, htmlAttributes:=Nothing)
这篇关于Html.ActionLink错误地拿起当前RouteValues的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!