I am currently trying to update a list of duties after the user has posted a new duty. I am trying to use Ajax doing this. However I am not shure how to use ajax for posting to my controller and then add to my list. How do I use my datafield in my ajax method and how do I update my list?
My controller:
[HttpPost]
Public ActionResult CreateDuty(PartialViewModel d)
{
db.DutiesTable.Add(d.OneDuty);
db.SaveChanges();
pv.DutyList = db.DutiesTable.ToList();
return View("Index");
}
My Ajax method:
<script>
$('#getDuty').click(function () {
$.ajax({
type: 'POST',
url: "/Home/CreateDuty",
data: {d : d}
}).success(function (data) {
alert(data + status);
});
});
</script>