MVC Ajax.Begin表单没有回发给actionresult

时间:2011-09-14 09:19:55

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

我最近将以下代码从使用常规html'形式'更改为使用ajax.beginform,但它不会回发到'PostCheckListCompleted'动作结果。任何想法为什么这不起作用?

        @Html.Grid(Model.ContactApplicationConditionList).RowAttributes(row => new Hash(@class => row.Item.IsSatisfied ? "completeRow" : "incompleteRow")).Columns(c =>
        {
            c.For(a => string.Format("{0:dd/MM/yyyy}", a.DateRequested)).Named("Date Requested");
            c.For(a => string.Format("{0:dd/MM/yyyy}", a.DateDeadline)).Named("Deadline Date");
            c.For(a => string.Format("{0:dd/MM/yyyy}", a.DateReceived)).Named("Date Received");
            c.For(a => a.Comment).Named("Comment");
            c.For(a => a.ApplicationOfferCondition.Name).Named("Checklist type");
            c.For(a => @Html.Raw(String.Format("<a href=\"#?w=380\" onclick=\"$('body').data('contactApplicationConditionId', '{0}' );\" rel=\"checklistUpdatePopup\" class=\"popupWindow\">Update</a>", a.ContactApplicationConditionId))).Named("Update");
            c.Custom(



                @<text>
                    @using (Ajax.BeginForm("PostCheckListCompleted", "Home", new AjaxOptions  { HttpMethod = "Post" }))
                    {
                        @Html.CheckBox("checkListCompleted", item.IsSatisfied, new { onclick = "$(this).parent('form:first').submit();" })
                        <input type="hidden" name="contactApplicationId" value=@ViewBag.ApplicationId />      
                        <input type="hidden" name="contactApplicationConditionId" value="@item.ContactApplicationConditionId" />     
                    }
                </text>

            ).Named("Complete");
        }).Attributes(@cellpadding => "0", @cellspacing => "0", @class => "table_results")

提前致谢。

2 个答案:

答案 0 :(得分:2)

您需要将jquery unobtrusive-ajax库添加到您的页面

<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>

并使用

更改该代码行
@using (Ajax.BeginForm("PostCheckListCompleted", "Home", new AjaxOptions  { HttpMethod = "Post", Url = Url.Action("PostCheckListCompleted") })) 

还要检查是否要为ajax回调设置目标,设置AjaxOptions的属性UpdateTargetId

答案 1 :(得分:-1)

您是否引用了ajax所需的脚本文件?

Microsoft.Ajax.js
MicrosoftMvc.Ajax.js

如果需要可能还有jquery