【问题标题】:ASP.NET MVC ActionLink renders erroneouslyASP.NET MVC ActionLink 呈现错误
【发布时间】:2013-05-10 09:22:32
【问题描述】:

SO 社区

我有以下问题:

如果我像这样渲染 ActionLink:

@Html.ActionLink(titleText, 
    Title.Href.TargetAction, 
    Title.Href.TargetController, 
    Title.Href.TargetRouteValues, 
    null)

渲染的元素是:

<a href="/eagle/Intervention/Edit_Inv?ID_INV=53165">        19/      2013</a>

但是如果我像这样添加一个对象作为 HTMLAttributes:

@Html.ActionLink(titleText, 
    Title.Href.TargetAction, 
    Title.Href.TargetController, 
    Title.Href.TargetRouteValues, 
    new {target="_blank"})

我得到以下标记:

<a href="/eagle/Intervention/Edit_Inv?Count=1&amp;Keys=System.Collections.Generic.Dictionary%602%2BKeyCollection%5BSystem.String%2CSystem.Object%5D&amp;Values=System.Collections.Generic.Dictionary%602%2BValueCollection%5BSystem.String%2CSystem.Object%5D" target="_blank">        19/      2013</a>

我有什么选择?

提前致谢, 西尔维乌。

【问题讨论】:

  • 你能给出 TargetRouteValues 的类型吗?

标签: asp.net-mvc-3 html-helper html.actionlink


【解决方案1】:

嗯,这很快!我破解了:

@Html.ActionLink(titleText, 
      Title.Href.TargetAction, 
      Title.Href.TargetController,
      Title.Href.TargetRouteValues, 
      new Dictionary<string, object> { { "target", "_blank" } })

这让我出来了。我没有为 HTMLAttributes 提供匿名对象,而是使用了 IDictionary,它现在就像一个魅力。

感谢您的关注,但是,尼克,您的解决方案无效;)

【讨论】:

    猜你喜欢
    • 2015-07-20
    • 2012-02-13
    • 2012-04-20
    • 1970-01-01
    • 1970-01-01
    • 2015-06-18
    • 1970-01-01
    • 2013-01-19
    • 1970-01-01
    相关资源
    最近更新 更多