This question is locked. New answers and comments are not allowed.
In the telerik example on the following link:
http://demos.telerik.com/aspnet-mvc/grid/editingajax
I was able to get it to work, but I am confused on how I am suppose save the changes to the database. So, the original ActionResult _SaveAjaxEditing:
public ActionResult _SaveAjaxEditing(int id)
{
EditableProduct product = SessionProductRepository.One(p => p.ProductID == id);
TryUpdateModel(product);
SessionProductRepository.Update(product);
return View(new GridModel(SessionProductRepository.All()));
}
I changed it to below, and it works, but I feel there is probably a better way. The RefundEntities represents the entity framework model I have. So, it looks like I needed to update the session and then update the database. Would this be correct? Any better way?
public ActionResult _SaveAjaxEditing(int id)
{
using (RefundEntities db = new RefundEntities())
{
EditableClient client = SessionClientRepository.One(c => c.ClientID == id);
var updateClient = db.tblClient.First(c => c.ClientID == id);
TryUpdateModel(client);
TryUpdateModel(updateClient);
if (ModelState.IsValid)
{
db.SaveChanges();
}
SessionClientRepository.Update(client);
}
return View(new GridModel(SessionClientRepository.All()));
}
http://demos.telerik.com/aspnet-mvc/grid/editingajax
I was able to get it to work, but I am confused on how I am suppose save the changes to the database. So, the original ActionResult _SaveAjaxEditing:
public ActionResult _SaveAjaxEditing(int id)
{
EditableProduct product = SessionProductRepository.One(p => p.ProductID == id);
TryUpdateModel(product);
SessionProductRepository.Update(product);
return View(new GridModel(SessionProductRepository.All()));
}
I changed it to below, and it works, but I feel there is probably a better way. The RefundEntities represents the entity framework model I have. So, it looks like I needed to update the session and then update the database. Would this be correct? Any better way?
public ActionResult _SaveAjaxEditing(int id)
{
using (RefundEntities db = new RefundEntities())
{
EditableClient client = SessionClientRepository.One(c => c.ClientID == id);
var updateClient = db.tblClient.First(c => c.ClientID == id);
TryUpdateModel(client);
TryUpdateModel(updateClient);
if (ModelState.IsValid)
{
db.SaveChanges();
}
SessionClientRepository.Update(client);
}
return View(new GridModel(SessionClientRepository.All()));
}