2012-04-29 41 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