放入htmlAttributes后,Ajax.ActionLink()不会触发

时间:2011-10-07 10:08:17

标签: asp.net-mvc-3 asp.net-mvc-2

我需要从集合中构建超链接列表(ActionLink)。在以下代码中应用htmlAttribute后,ActionLink不会触发回服务器。

   @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 }

    }

1 个答案:

答案 0 :(得分: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 })

}