DataManager Stringify 0 and False Values

Hi.
I have a test project:

Model:
    public class Foo
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public FooType Type { get; set; }
        public bool Disabled { get; set; }
    }
    public enum FooType
    {
        Type1 = 0,
        Type2 = 1
    }

Controller:
    public class FooController : Controller
    {
        public ActionResult Index()
        {
            var foos = new List();
            for (int i = 1; i <= 1000; i++)
            {
                foos.Add(new Foo
                {
                    Id = i,
                    Name = $"Foo #{i}",
                    Type = i % 2 > 0 ? FooType.Type1 : FooType.Type2,
                    Disabled = i % 2 > 0 ? false: true
                });
            }
            return View(foos);
        }
        [HttpPost]
        public ActionResult Create(Foo value)
        {
            return Json(value, JsonRequestBehavior.AllowGet);
        }
        [HttpPost]
        public ActionResult Update(Foo value)
        {
            return Json(value, JsonRequestBehavior.AllowGet);
        }
        [HttpPost]
        public ActionResult Delete(int key)
        {
            return Json(key, JsonRequestBehavior.AllowGet);
        }
    }

View:
@model IEnumerable
@{
    ViewBag.Title = "Index";
    var types = new object[] { new { Type = 0, TypeName = "Type1" }, new { Type = 1, TypeName = "Type2" } };
    var disables = new object[] { new { Disable = "false", DisableName = "No" }, new { Disable = "true", DisableName = "Yes" } };
}

@(Html.EJS().Grid("Grid")
    .DataSource(dataManager =>
    {
        dataManager.Json(Model.ToArray())
            .InsertUrl("/Foo/Create")
            .UpdateUrl("/Foo/Update")
            .RemoveUrl("/Foo/Delete")
            .Adaptor("RemoteSaveAdaptor");
    })
    .AllowSorting()
    .AllowFiltering()
    .Columns(col =>
    {
        col.Field("Name").HeaderText("Name").Width("150").Add();
        col.Field("Type").ForeignKeyField("Type").ForeignKeyValue("TypeName").DataSource(types).HeaderText("Type").Width("150").Add();
        col.Field("Disable").ForeignKeyField("Disable").ForeignKeyValue("DisableName").DataSource(disables).HeaderText("Disable").Width("150").Add();
    })
    .AllowPaging()
    .FilterSettings(filter => { filter.Type(Syncfusion.EJ2.Grids.FilterType.Menu); })
    .EditSettings(edit =>
    {
        edit.AllowAdding(true)
        .AllowEditing(true)
        .AllowDeleting(true)
        .ShowDeleteConfirmDialog(true)
        .Mode(Syncfusion.EJ2.Grids.EditMode.Normal);
    })
    .Toolbar(new List() { "Add", "Edit", "Delete", "Update", "Cancel" })
    .Render())

Afther run the application, I have see this JSON in result:
...
  "dataSource": new ej.data.DataManager({
  "adaptor": new ej.data.RemoteSaveAdaptor(),
  "insertUrl": "/Foo/Create",
  "removeUrl": "/Foo/Delete",
  "updateUrl": "/Foo/Update",
  "json": [
    {
      "Id": 1,
      "Name": "Foo #1"
    },
    {
      "Id": 2,
      "Name": "Foo #2",
      "Type": 1,
      "Disabled": true
    },
    {
      "Id": 3,
      "Name": "Foo #3"
    },
    {
      "Id": 4,
      "Name": "Foo #4",
      "Type": 1,
      "Disabled": true
    },
...
Fields <"Type": 0> and <"Disabled": false> aren't exist! 
My ForeignKeyField's don't work.

If I change  the enum Type1=1 and Type2=2, ForeignKeyField is work.
See attached project.

Thanks.


Attachment: WebApplication2_a4a30b19.zip

2 Replies

IR Isuriya Rajan Syncfusion Team March 27, 2018 05:31 PM UTC

Hi  Kabanets, 
 
Thanks for contacting Syncfusion support. 
 
While serializing the Boolean values false was not include .This is default value handling behavior of JSON.Net serialization .So this  may be problem for false/0 value not including in your dataset. 
 
 
For this we suggest to use this below solution in your application: 
 
 
[JsonProperty(DefaultValueHandling = Newtonsoft.Json.DefaultValueHandling.Include)] 
   
  public bool Disabled { get; set; } 
 
Also we will consider this for “Foreignkey mapping is not applying when the key value is 0/false value” as a bug and it will be include in our release which we planned to be rolled out on  mid of April  2018. 
 
Please let us know if the above specified issue not the one you have faced in your application. 
 
Regards, 
Isuriya R 
 
 



IR Isuriya Rajan Syncfusion Team April 13, 2018 10:18 AM UTC

Hi Kabanets, 

We are glad to announce that patch release(V 16.1.34 ) is rolled out successfully and In that release, we have added the fix for “Foreignkey mapping is not applying when the key value is 0/false value” issue.   
  
Refer any one of the below steps to update the packages   :  
  
  1. Using the “npm update” command.
  
This will update all our listed packages and also will install missing packages too.   
Please refer the below link for your reference: 
  
  
  
  1. Using the “npm install @syncfusion/ej2” command
  
This command will  automatically install our latest version of npm package 
You can get the npm Package form below location: 
                       
                         Npm Packages: https://www.npmjs.com/~syncfusionorg  
  
If you were using the cdn . Please get the latest from this link:  
  

Regards,   
Isuriya R 

 


Loader.
Up arrow icon