Reputation: 219
I have recently changed the below code from using a regular html 'form' to using an ajax.beginform, but it does not post back to the 'PostCheckListCompleted' actionresult. Any ideas why this is not working?
@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" [email protected] />
<input type="hidden" name="contactApplicationConditionId" value="@item.ContactApplicationConditionId" />
}
</text>
).Named("Complete");
}).Attributes(@cellpadding => "0", @cellspacing => "0", @class => "table_results")
Thanks in advance.
Upvotes: 1
Views: 1274
Reputation: 9143
Have you referenced ajax required script files?
Microsoft.Ajax.js
MicrosoftMvc.Ajax.js
and possibly jquery if required
Upvotes: -1
Reputation: 3191
You need to add the jquery unobtrusive-ajax library to your page
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
and change that code line with
@using (Ajax.BeginForm("PostCheckListCompleted", "Home", new AjaxOptions { HttpMethod = "Post", Url = Url.Action("PostCheckListCompleted") }))
Check also if you want to set a target for ajax callback, setting the property UpdateTargetId of AjaxOptions
Upvotes: 2