We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Using ViewModel with grid

Thread ID:

Created:

Updated:

Platform:

Replies:

127075 Oct 24,2016 05:30 PM UTC Oct 25,2016 12:41 PM UTC ASP.NET MVC 1
loading
Tags: Grid
Michael Lambert
Asked On October 24, 2016 05:30 PM UTC

I'm using ViewModel instead of Viewbag but need to understand how best to handle updates. In this snippet I am only using a single datasouce in the the model to keep it simple, but in the production I have several other data sources that I'll need to include, hence the ViewModel approach as opposed to several Viewbag definitions. The following code does work, though I can only send back the json code in the Update action (not a ViewModel). Need assistance with best practices on how best to handling working/updated with ViewModels.

Mike

View:
@(Html.EJ().Grid("TestGrid")
.Datasource(ds => ds.Json(Model).UpdateURL("/Requests/Update").InsertURL("/Requests/Insert").RemoveURL("/Requests/Remove").Adaptor(AdaptorType.RemoteSaveAdaptor))
.EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing(); })

Controller:
public ActionResult Grid()
{
return View(db.Requests.ToList());
}

public ActionResult Update(Request value)
{
Request req = db.Requests.Single(o => o.RequestID == value.RequestID);
db.Entry(req).CurrentValues.SetValues(value);
db.Entry(req).State = EntityState.Modified;
req.BU = value.BU;
db.SaveChanges();
var result = db.Requests.ToList();
return Json(new { result = result, count = result.Count }, JsonRequestBehavior.AllowGet);
}


Jayaprakash Kamaraj [Syncfusion]
Replied On October 25, 2016 12:41 PM UTC

Hi Michael, 
 
Thank you for contacting Syncfusion support. 
 
While performing CRUD operation in Grid with IsIdentity column it is essential to return updated data in Json format from controller. Void type also supports so if you are not using isIdentity column in Grid Use Void type because it is not necessary to return updated data while using void type and also changes will be reflected automatically in database and in Grid. Please refer to the below code example.   
 
        //Perform update 
        public void PerformUpdate(OrderTable value) 
        { 
 
            db.Entry(value).State = EntityState.Modified; 
            db.SaveChanges(); 
        } 
 
Regards, 
 
Jayaprakash K. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;