i think the following code you can understand.
first, create a ajax form with
- RefreshAjaxList: the name ajax action of current controller.
- string.empty (optional)
- ajax option.
- id of form (optional)
- when click status, we will edit the status call server to update the status.
- after edit the status, we call submit button to call RefreshAjaxList. the button is "display:none"
- in this example, i have one controller: AjaxController with 2 actions:
enter code here
public ActionResult UpdateStatus(int contactId, Status contactStatus)
{
ContactRepository repo = new ContactRepository();
repo.UpdateStatus(contactId, contactStatus);
return Json("success:true");
}
[AcceptVerbs(HttpVerbs.Post)]
[ActionName("RefreshAjaxList")]
public ActionResult RefreshContact()
{
ContactRepository repo = new ContactRepository();
IList<Contact> list = repo.List();
return PartialView("AjaxUc/AjaxList", repo.List());
}
var status = { active: 1, inactive: 0 };
function editStatus(cell, id, active) {
if (active)
cell.innerHTML = "Active" +
"Inactive";
else
cell.innerHTML = "Active" +
"Inactive";
}
function updateStatus(radio, id, active) {
if (radio.checked != active) {
if (confirm("Do you want to change the status of the contract?")) {
if (active)
cStatus = status.active;
else
cStatus = status.inactive;
$.ajax({
url: 'Ajax/UpdateStatus',
dataType: "json",
data: { contactId: id, contactStatus: cStatus },
success: function(html) {
jQuery("#divAjaxList").submit();
},
error: function(request, desc, ex) {
alert(desc);
}
});
}
}
}
<% using (Ajax.BeginForm("RefreshAjaxList", "abc", new AjaxOptions() { UpdateTargetId = "divContent" }, new { @id = "divAjaxList" }))
{%>
Id
FirstName
LastName
Phone
Email
Status
|
, );">
<% } %>
for more info, mail to [email protected] for further discussion.
hope this can help u.