2013-05-10 92 views
1

SO社区ASP.NET MVC的ActionLink呈现错误

我有以下问题:

如果我呈现这样一个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> 

什么是我选择这里?

在此先感谢, Silviu。

+0

你能给TargetRouteValues的类型? – Satpal 2013-05-10 09:36:04

+0

RouteValueDictionary – 2013-05-10 09:47:14

回答

1

嗯,这很快!我破解它:

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

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

谢谢你的关心,但是,尼克,你的解决方案是无效的;)