2011-10-07 48 views
2

我需要從集合中創建超鏈接(ActionLink)的列表。在以下代碼中應用htmlAttribute後,ActionLink不會觸發回服務器。Ajax.ActionLink()在放置htmlAttributes後不會觸發

@foreach (MillitarySlot slot in item.MondaySlots) 
    { 
     @Ajax.ActionLink(linkText: @slot.SlotText, 
     actionName: "CreateIndex", 
     routeValues: new { someId = slot.Id }, 
     ajaxOptions: new AjaxOptions 
     { 
      UpdateTargetId = "divCreateSchedule", 
      InsertionMode = InsertionMode.Replace, 
      HttpMethod = "post" 
     }, 
     //After adding following htmlAttribule, view does not trigger call 
     htmlAttributes: new { title = slot.ToolTip, style = "color:" + slot.Color } 

    } 

回答

2

嘗試添加托架slot.Color之後}例如..

@foreach (MillitarySlot slot in item.MondaySlots) 
{ 
    @Ajax.ActionLink(linkText: @slot.SlotText, 
    actionName: "CreateIndex", 
    routeValues: new { someId = slot.Id }, 
    ajaxOptions: new AjaxOptions 
    { 
     UpdateTargetId = "divCreateSchedule", 
     InsertionMode = InsertionMode.Replace, 
     HttpMethod = "post" 
    }, 
    //After adding following htmlAttribule, view does not trigger call 
    htmlAttributes: new { title = slot.ToolTip, style = "color:" + slot.Color }) 

} 
+0

foreach循環就完成了。沒有編譯錯誤。雖然粘貼代碼,我錯過了最後一個括號令牌...... :( – StartingFromScratch

+0

確定你能查看頁面源代碼並讓我知道爲鏈接生成了什麼html嗎? – WooHoo

+0

感謝您的追蹤!但是,我選擇了jQuery的路徑的@ Ajax.ActionLink和有東西在運行。[鏈接](http://stackoverflow.com/questions/7686542/jquery-need-to-show-modal-dialog-on-any-anchor-link-click-on-該頁面)的另一個職位。 – StartingFromScratch