[Key]public int UserId {get;set;}public string Name {get;set;}public virtual UserType UserType {get;set;}
[Key]public int UserTypeId {get;set;}public string Name {get;set;}
ViewBag.TypesList = dbContext.UserTypes.ToList();return View();
var result = dbContext.Users.ToList();
return Json(new{ result, count = result.Count() });
var result = dbContext.Users.Include(p => p.Usertype).ToList();
return Json(new{ result, count = result.Count() });
@(Html.EJ().Grid<user>("tbListaSistemi") .Datasource(ds => ds.URL(Url.Action("GetList")).Adaptor(AdaptorType.UrlAdaptor)) .AllowPaging() .PageSettings((p) => { p.PageCount(20).PageSize(30); }) .Columns(col => { col.Field(p => p.UserId).IsPrimaryKey(true).Visible(false).Add();
col.Field(p => p.Name).Add();
col.Field(p => p.UserType.UserTypeId).DataSource(ViewBag.TypesList).EditType(EditingType.Dropdown).Width(150).Add(); |
@(Html.EJ().Grid<user>("tbListaSistemi") . . . .Columns(col => { . . . col.Field("UserType.UserTypeId").DataSource(ViewBag.TypesList).EditType(EditingType.Dropdown).Add(); })) |
Hi Omar,
Thanks for using Syncfusion products.
From the provided code example we understood that you want to display the related entities in the grid. To do so, please refer to the below code example.
@(Html.EJ().Grid<user>("tbListaSistemi")
.Datasource(ds => ds.URL(Url.Action("GetList")).Adaptor(AdaptorType.UrlAdaptor))
.AllowPaging()
.PageSettings((p) => { p.PageCount(20).PageSize(30); })
.Columns(col =>
{
col.Field(p => p.UserId).IsPrimaryKey(true).Visible(false).Add();
col.Field(p => p.Name).Add();
col.Field(p => p.UserType.UserTypeId).DataSource(ViewBag.TypesList).EditType(EditingType.Dropdown).Width(150).Add();
}))
But we have a bug in defining the complex field names through lambda expression and hence we considered this requirement “Lambda-based field definitions is not working for complex property” as bug and a support incident has been created under your account to track the status of this requirement. Please log on to our support website to check for further updates.
https://www.syncfusion.com/account/login?ReturnUrl=/support/directtrac/incidents
For now to show related entities in the grid, use the below code example.
@(Html.EJ().Grid<user>("tbListaSistemi")
. . .
.Columns(col =>
{
. . .
col.Field("UserType.UserTypeId").DataSource(ViewBag.TypesList).EditType(EditingType.Dropdown).Add();
}))
The above code example will work when the related entities are eager loaded(using Include).
Regards,
Madhu Sudhanan. P
@(Html.EJ().Grid<User> ("tbListaSistemi") .Datasource(ds => ds.URL(Url.Action("GetList")).Adaptor(AdaptorType.UrlAdaptor)) .EditSettings(e => e.AllowEditing()) .AllowPaging() .Columns(col => { . . . . col.Field("UserType.UserTypeId") .DataSource(ViewBag.dropdata) .EditType(EditingType.Dropdown) .Width(150) .Add(); List<dropData> drop = new List<dropData>(); public ActionResult Index() { drop.Add(new dropData(1,"1")); . . . .. drop.Add(new dropData(5,"5")); ViewBag.dropdata = drop; return View(); } public class dropData { public dropData() { } public dropData(int val, string txt) { this.value = val; this.text = txt; } public int value { get; set; } public string text { get; set; } |
col.Field("UserType.Name").Width(150).Add(); |
ViewBag.dropdata = dbContext.UserTypes.Select(p => new dropData() { value = p.UserTypeId/*value is 2*/, text = p.Name/*text is UserType 2*/ }).ToList(); |
public ActionResult Index() { drop.Add(new dropData(”UserType 1”,"UserType 1")); . . . .. drop.Add(new dropData(“UserType 5”,"UserType 5")); ViewBag.dropdata = drop; return View(); } |