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. Image for the cookie policy date

Sample error

Hi, I am following this sample for CRUD grid, but the help is confusing, since the both show different code in yellow below...

http://mvc.syncfusion.com/demos/web/grid/externalformediting
http://mvc.syncfusion.com/demos/web/grid/inlineformediting

I have questions for CRUD with grid remote save - the samples and help pages don't match,
  1. First with this paging in grid sample, when the user navigates to page 3 or 4 in the grid, how does the grid get those records, its done automatically by the adaptor, or do I have to handle that?
  2. Code in the samples is this for all RemoteSave CRUD, do the action have to return JSON data only?
  3. Should they return the full list or just the edited value - In some samples/places the Actions are returning the deleted data and other places its returning the full list, for e.g. http://mvc.syncfusion.com/demos/web/grid/externalformediting here ExternalInsert is returning value, but in the help page sample, its returning the full list but here its returning the full llist/Data https://help.syncfusion.com/aspnetmvc/grid/data-adaptors?cs-save-lang=1&cs-lang=csharp#remotesave-adaptor

http://mvc.syncfusion.com/demos/web/grid/externalformediting public ActionResult ExternalUpdate(EditableOrder value) { OrderRepository.Update(value); var data = OrderRepository.GetAllRecords(); return Json(value, JsonRequestBehavior.AllowGet); } public ActionResult ExternalInsert(EditableOrder value) { OrderRepository.Add(value); var data = OrderRepository.GetAllRecords(); return Json(value, JsonRequestBehavior.AllowGet); } public ActionResult ExternalDelete(int key) { OrderRepository.Delete(key); var data = OrderRepository.GetAllRecords(); return Json(data, JsonRequestBehavior.AllowGet); }

But Confusing information here vs... https://help.syncfusion.com/aspnetmvc/grid/data-adaptors?cs-save-lang=1&cs-lang=csharp#remotesave-adaptor

namespace EJGrid.Controllers { public class HomeController : Controller { public ActionResult Index() { var data = OrderRepository.GetAllRecords(); ViewBag.dataSource = data; return View(); } public ActionResult Update(EditableOrder value) { OrderRepository.Update(value); var data = OrderRepository.GetAllRecords(); return Json(data, JsonRequestBehavior.AllowGet); } public ActionResult Insert(EditableOrder value) { OrderRepository.Add(value); var data = OrderRepository.GetAllRecords(); return Json(data, JsonRequestBehavior.AllowGet); }


thanks


2 Replies

ME Megatron February 15, 2017 11:25 PM UTC

One more point -
  1. How is the JSON error handled on Grid CRUD? is it passed in the header value automatically, how does the grid show the errors to the user on client side?
  2. In the sample you have RemoveURL, (but no deleteURL are they the same or not needed?), the namingURL does not follow CRUD
I ask because, in some of your samples for RemoveURL it shows Remove code which works if there FK relationships, but the Demo page has Delete code which fails with FK - which is correct? And, when I use that sample for removeURL errors out and not working if there are child relationships, if you could also please show how to handle this safely for both FK/EF child elements and regular collection so that the Grid RemoveURL remoteAdaptor works in both scenarios

If (SfGridCollectoinWithFK == true) // on the link shows the difference after I did some troubleshooting, but the sample case is not show in the help grid. http://stackoverflow.com/a/17726414/6085193 I am guessing this is when there are Foreign Key attached to the grid.
            { removeURL }
else
        if (SfGridCollectoinNo == true)
                { deleteURL } // but there is not delte URL on the adaptor
Basically, the gird needs an easy way (sample) to handle deletes regardless of the bindings.



JK Jayaprakash Kamaraj Syncfusion Team February 16, 2017 11:31 AM UTC

Hi Megatron, 

Thank you for contacting Syncfusion support. 
Query 1: First with this paging in grid sample, when the user navigates to page 3 or 4 in the grid, how does the grid get those records, its done automatically by the adaptor, or do I have to handle that? 
RemoteSaveAdaptor is extended from the JsonAdaptor of the DataManager and it is used for binding local data and performs all DataManager queries in client-side. It interacts with server-side for CRUD operations to pass the modified records. So, no need to handle all the operations(paging/sorting/..etc) in server side while using RemoteSaveAdaptor. 
Query 2: Code in the samples is this for all RemoteSave CRUD, do the action have to return JSON data only? 
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(); 
        } 
Query 3: Should they return the full list or just the edited value - In some samples/places the Actions are returning the deleted data and other places its returning the full list, 
We can return full list or modified values or you can 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 
        //Perform update 
        public void PerformUpdate(OrderTable value) 
        { 
 
            db.Entry(value).State = EntityState.Modified; 
            db.SaveChanges(); 
        } 
Query 4: How is the JSON error handled on Grid CRUD? is it passed in the header value automatically, how does the grid show the errors to the user on client side? 
We have already discussed the same in following knowledge base documents. 


We have created a sample based on your requirement. In that sample we have handled validations in server side grid operations(insert/update/delete) and also we have displayed error message in alert box using ActionFailure event . ActionFailure event triggered for every grid action server failure event. Please refer to the below code example and sample. 
                                                                                         

@(Html.EJ().Grid<object>("FlatGrid") 
           .Datasource(ds => ds.URL("/Grid/DataSource").UpdateURL("/Grid/Update").InsertURL("/Grid/Insert").Adaptor(AdaptorType.UrlAdaptor)) 
     
        }).ClientSideEvents(eve => { eve.ActionFailure("Failure"); })) 
<script type="text/javascript"> 
    function Failure(args) { 
        var popupObj = $("#FlatGrid").data("ejWaitingPopup"); 
        popupObj.hide(); 
        this.cancelEdit(); 
        var str = ""; 
        str = args.error.statusText; 
        alert(str); 
    } 
</script> 
 
GridController.cs 
public ActionResult DataSource(DataManager dm) 
        { 
            DataOperations ds = new DataOperations(); 
 
            var data = ds.Execute(OrderRepository.GetAllRecords().ToList(), dm); 
            return Json(new { result = data, count = db.Orders.ToList().Count }, JsonRequestBehavior.AllowGet); 
        } 
 
        public ActionResult Update(EditableOrder value) 
        { 
            if (!ModelState.IsValid) 
            { 
                var message = string.Join(" | ", ModelState.Values 
       .SelectMany(v => v.Errors) 
       .Select(e => e.ErrorMessage)); 
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest, message); 
            } 
            EditableOrder old = OrderRepository.GetAllRecords().Where(o => o.OrderID == value.OrderID).SingleOrDefault(); 
            return Json(OrderRepository.GetAllRecords(), JsonRequestBehavior.AllowGet); 
        } 


Query 5: In the sample you have RemoveURL, (but no deleteURL are they the same or not needed?), the namingURL does not follow CRUD I ask because, in some of your samples for RemoveURL it shows Remove code which works if there FK relationships, but the Demo page has Delete code which fails with FK - which is correct?                
Before proceeding please share us the following details. 
1.       Share your grid rendering code example(both client and server) 
2.       Share the Demo page link ? (Demo page has Delete code which fails with FK )  
3.       Share the link about deleteURL.  
4.       Essential studio and browser version details. 
5.       Share more details about your query . 
6.       If possible, provide an issue reproducing sample or hosted link  
 
Regards, 
 
Jayaprakash K. 


Loader.
Up arrow icon