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