问题
SO community
I have the following issue:
If i render an ActionLink like this:
@Html.ActionLink(titleText,
Title.Href.TargetAction,
Title.Href.TargetController,
Title.Href.TargetRouteValues,
null)
the rendered element is:
<a href="/eagle/Intervention/Edit_Inv?ID_INV=53165"> 19/ 2013</a>
but if i add an object as HTMLAttributes like this:
@Html.ActionLink(titleText,
Title.Href.TargetAction,
Title.Href.TargetController,
Title.Href.TargetRouteValues,
new {target="_blank"})
i get the following markup:
<a href="/eagle/Intervention/Edit_Inv?Count=1&Keys=System.Collections.Generic.Dictionary%602%2BKeyCollection%5BSystem.String%2CSystem.Object%5D&Values=System.Collections.Generic.Dictionary%602%2BValueCollection%5BSystem.String%2CSystem.Object%5D" target="_blank"> 19/ 2013</a>
What are my options here?
Thanks in advance, Silviu.
回答1:
Well, this was quick! I cracked it:
@Html.ActionLink(titleText,
Title.Href.TargetAction,
Title.Href.TargetController,
Title.Href.TargetRouteValues,
new Dictionary<string, object> { { "target", "_blank" } })
This got me out. Instead of providing an anonymous object for the HTMLAttributes, i used an IDictionary, and it now works like a charm.
Thanks for the interest, however, Nick, your solution is not valid ;)
来源:https://stackoverflow.com/questions/16478988/asp-net-mvc-actionlink-renders-erroneously