Asp.net Mvc5.1和BootStrap 3将属性添加到Html.ActionLink

时间:2014-02-25 21:30:20

标签: twitter-bootstrap-3 asp.net-mvc-5 actionlink

我想将Html.ActionLink作为链接:

 <a href="http://www.mysite.com" class="screenshot restau" rel="~/Content/Tooltip/MyImage.jpg" >To My Site</a> 

所以我试试:

 <li>@Html.ActionLink("Accueil", "Index", "Home",new {href="http://www.mysite.com"}, new { @class="screenshot restau" }, new { rel="~/Content/Tooltip/MyImage.jpg"})</li>

但是我得到了一个错误:

'System.Web.Mvc.HtmlHelper<dynamic>' does not contain a definition for 'ActionLink' and the best extension method overload 'System.Web.Mvc.Ajax.AjaxExtensions.ActionLink(System.Web.Mvc.AjaxHelper, string, string, string, System.Web.Routing.RouteValueDictionary, System.Web.Mvc.Ajax.AjaxOptions, System.Collections.Generic.IDictionary<string,object>)' has some invalid arguments

如果我删除了href属性,它也不起作用,我将其作为Html呈现:

a rel="~/Content/Tooltip/LeSoufflotPatit.jpg" href="/?class=screenshot%20restau">Accueil

我可以在哪里看到我的css类作为编码问题而且我有一个奇怪的href

我缺少什么,我不明白

1 个答案:

答案 0 :(得分:0)

我相信你只需要使用1个新{}

<li>@Html.ActionLink("Accueil", "Index", "Home",new {href="http://www.mysite.com" ,@class="screenshot restau", rel="~/Content/Tooltip/MyImage.jpg"})</li>

此外,我不确定您是否可以使用href,因为ActionLink会为您生成href