Hello I currently have an application that uses MVC 5 and Entity Framework 6. I have a view with the current code:
<tr>
<td class="infoCell">@Html.LabelFor(x => Model.PersonInfo.firstName, "First Name:")</td>
<td class="infoCell">@Html.EditorFor(x => Model.PersonInfo.firstName)</td>
<td class="infoCell">@Html.LabelFor(x => Model.PersonInfo.lastName, "Last Name: ")</td>
<td class="infoCell">@Html.EditorFor(x => Model.PersonInfo.lastName)</td>
</tr>
I also have a controller method with the code:
[HttpPost]
public ActionResult Save(PersonViewModel PersonViewModel)
{
PersonService PSVC = new PersonService();
PSVC.Save(PersonViewModel.PersonInfo, PersonViewModel.ModeInfo, PersonViewModel.PersonISS, PersonViewModel.Injury);
using (MEDICSContext db = new MEDICSContext())
{
db.SaveChanges();
}
return PartialView("_People");
}
This controller is calling my service method Save with the code:
public void Save(PersonInfo PersonInfo, PersonModeInfo PersonModeInfo, PersonISS PersonISS, Injury Injury)
{
using (MEDICSContext db = new MEDICSContext())
{
db.Entry(PersonInfo).State = EntityState.Modified;
db.Entry(PersonModeInfo).State = EntityState.Modified;
db.Entry(PersonISS).State = EntityState.Modified;
db.Entry(Injury).State = EntityState.Modified;
db.SaveChanges();
}
}
I want to set up a button in the view that will save any changes i make in the "editorFor" fields without leaving the view. Im not entirely sure how to tie a button to the action in the controller and how to update the page without having to reload the page. Any help is much appreciated.