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)
.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")
"{{if IsActive}}" +
"{{else}}" +
"{{/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.