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

Passing Data to server in the URL Adaptor Inline form

Hello Guys,

I am using the Syncfusion MVC grid I am facing the problem while passing data to a server in sync fusion when we update the grid. Every time the update method it gives me model properties as null only even when everything seems right.
Below is my code. can anyone know what I am doing wrong or what I am missing?

Below is CSHTML code

@(Html.EJ().Grid("Products")
                                                   .Datasource(datasource => datasource.URL(@Url.Action("Search")).UpdateURL(@Url.Action("Update"))
                                                   .Adaptor(AdaptorType.UrlAdaptor))
                                                    .EditSettings(edit => { edit.AllowAdding().AllowEditing().EditMode(EditMode.InlineForm).ShowConfirmDialog(true).TitleColumn("Code"); })
                                                        .ToolbarSettings(toolbar =>
                                                        {
                                                            toolbar.ShowToolbar().ToolbarItems(items =>
                                                            {
                                                                items.AddTool(ToolBarItems.Add);
                                                                items.AddTool(ToolBarItems.Edit);
                                                                items.AddTool(ToolBarItems.Update);
                                                                items.AddTool(ToolBarItems.Cancel);
                                                            });
                                                        })
                                                  .AllowFiltering()
                                                  .AllowSorting()
                              .SortSettings(builder => builder.SortedColumns(col => col.Field("Code").Direction(SortOrder.Ascending).Add()))
                                                  .AllowPaging()
                                                  .AllowResizing()
                                                  .EnableHeaderHover()
                                                  .EnableRowHover(false)
                                                  //.AllowSelection(false)
                                                  .FilterSettings(filter => { filter.FilterType(FilterType.Excel).FilteredColumns(col => col.Field("Available").Operator(FilterOperatorType.Equals).Value("Enabled").Add()); })
                                                  .Columns(col =>
                                                  {
                                                      col.Field(x => x.IsVerify)
                                                          .HeaderText("JS")
                                                          .Template("")
                                                          .TextAlign(TextAlign.Center).AllowEditing(false)
                                                          .Width(45)
                                                          .Add();
                                                      col.Field(x => x.Id)
                                                           .HeaderText("Id")
                                                           .TextAlign(TextAlign.Left).IsPrimaryKey(true).AllowEditing(false).Visible(false)
                                                           .Width(100)
                                                           .Add();
                                                      col.Field(x => x.Code)
                                                        .Template("
"
                                                                  + "{{:Code}}"
                                                                  + "
")
                                                        .HeaderText("Code")
                                                        .TextAlign(TextAlign.Left)
                                                        .ValidationRules(v => v.AddRule("required", true))
                                                        .Width(100)
                                                        .Add();
                                                      col.Field(x => x.Description)
                                            .HeaderText("Description").AllowEditing(false)
                                            .TextAlign(TextAlign.Left)
                                            .Width(100)
                                            .Add();
                                                      col.Field(x => x.Handing)
                                              .HeaderText("Handing")
                                              .TextAlign(TextAlign.Left).AllowEditing(false)
                                              .Width(45)
                                              .Add();
                                                      col.Field(x => x.Range)
                                              .HeaderText("Range")
                                              .TextAlign(TextAlign.Left).AllowEditing(false)
                                              .Width(120)
                                              .Add();
                                                      col.Field(x => x.Rule)
                                             .HeaderText("Rule")
                                             .TextAlign(TextAlign.Left).AllowEditing(false)
                                             .Width(100)
                                             .Add();
                                                      col.Field(x => x.Available)
                                              .Width(70)
                                              .HeaderText(" ")
                                              .CssClass("available")
                                              .TextAlign(TextAlign.Left).AllowEditing(false)
                                              .Add();
                                                      col.HeaderText("Actions")
                                              .Template(" View" +
                                              "Edit" +
                                              "Duplicate" +
                                              "{{if IsActive}}" +
                                              "Disable" +
                                              "{{else}}" +
                                              "Enable" +
                                              "{{/if}}"
                                          ).AllowEditing(false)
                                            .TextAlign(TextAlign.Center)
                                            .Width(140).
                                            Add();

And below is my C# code of the controller

        [HttpPost]
        public ActionResult Search(DataManager dataManager)
        {
            var products = _productsService.GetAllProducts().ToList();

            var data = ApplySearch(dataManager, products, out var count);

            return Json(new { result = data, count });
        }

        [HttpPost]
        public ActionResult Update(ProductRowViewModel model)
        {
             HttpContext.Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest;
            return Json(new { Success = false, Message = "Code must be unique!" }, JsonRequestBehavior.AllowGet);
        }

All the properties in the model are coming null. however the model is perfect
I am using the URL Adapter.





3 Replies

VN Vignesh Natarajan Syncfusion Team November 16, 2018 11:47 AM UTC

Hi Sandip, 
 
 
Thanks for contacting Syncfusion support.  
 
From your query, we understand that you are facing issue while updating the record in server side. While updating the records you have tried to receive the parameters as model (public ActionResult Update(ProductRowViewModel model) in server side instead of Value, so it returns the object as null. In Grid, we have passed the updated parameters in the form of objects and in name of value.  
 
So we suggest you to follow as like below code example 
 
 
@(Html.EJ().Grid<OrdersView>("Grid") 
                              .Datasource(ds => ds.URL("/Grid/UrlDataSource").UpdateURL("/Grid/Update").InsertURL("/Grid/Insert").RemoveURL("/Grid/Delete") 
                                 .Adaptor(AdaptorType.UrlAdaptor)) 
                                                 
) 
   
  public ActionResult Update(Orders value) 
        { 
             
            Orders val = order.Where(or => or.OrderID =value.OrderID).FirstOrDefault(); 
            val.OrderID = value.OrderID; 
            val.EmployeeID = value.EmployeeID; 
            val.CustomerID = value.CustomerID; 
            val.ShipCity = value.ShipCity; 
            return Json(value); 
        } 
 
 
Refer to the screenshot for the output 
 
 
 
 
 
For your convenience we have prepared a sample which can be downloaded from below link 
 
 
Please get back to us if you need any further assistance. 
 
Regards, 
Vignesh Natarajan 



SA Sandip November 19, 2018 12:23 AM UTC

Thanks. After applying its working for me.


VN Vignesh Natarajan Syncfusion Team November 19, 2018 08:23 AM UTC

Hi Sandip, 


Thanks for the update. 


We are glad to hear that your query has been resolved by your solution. 


Please get back to us if you have further queries. 


Regards, 
Vignesh Natarajan  


Loader.
Live Chat Icon For mobile
Up arrow icon