2012-04-29 34 views
1
<% foreach (var item in Model) { %> 

     <table width="100%" class="topicContainer"> 
      <tr> 
      <td> <%: Html.DisplayFor(modelItem => item.headerclob) %></td> 
      </tr> 
      <tr> 
      <td><%: Html.ActionLink("ViewTopic", "ViewTopic","Forum" , 
       new { id=item.topicId },null) %></td> 
      </tr> 
     </table> 

     <% } %> 

我想链接ViewTopic item.headerclob应该显示在超链接而不使用Razor。html.actionlink以C#变量作为参数

我也想应用它的CSS。

回答

2

我认为下面的代码应该工作

<%: Html.ActionLink("item.headerclob, "ViewTopic","Forum" , 
       new { id=item.topicId },null) %> 

它使用以下格式

public static string ActionLink(this HtmlHelper htmlHelper, 
           string linkText, 
           string actionName, 
           string controllerName, 
           object values, 
           object htmlAttributes) 

如果您正在使用MVC 3,那么你可以只使用“item.topicId”,而不是“ “id = item.topicId”

编辑 是的,它工作,但从item.headerClob删除分号后

<%: Html.ActionLink(item.headerclob, "ViewTopic","Forum" , 
       new { id=item.topicId },null) %> 

编辑 添加一个类动作链接,然后用你的CSS文件中设置必要的属性

<%: Html.ActionLink(item.headerclob, "ViewTopic","Forum" , 
        new { id=item.topicId , @class = "YourClass"},null) %> 

现在你可以应用CSS属性设置CSS属性给他人

操作链接

编辑 如果你不想使用剃须刀,我可以建议你通过你自己建立锚点,如跟随ing

<a href="<%=Url.Action("ViewTopic", "Forum",new { id=item.topicId})%>" class="YourClass"> item.headerclob </a> 
+0

是的,这是一个轻微的错误,我刚刚看到它。必须错误地输入双引号。请将此标记为答案,如果这有助于谢谢 – Jayanga

+0

如何将CSS应用于Html.ActionLink – coder25

+0

编辑答案审查它 – Jayanga