ASP.NET MVC ActionLink renders erroneously

余生颓废 提交于 2019-12-08 03:36:28

问题


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&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>

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!