The form throws this exception when a User has Department. View with form:
@model DMDPace.DataAccess.DomainModels.User;
@(Html.Kendo().Form<User>()
.Name("User")
.HtmlAttributes(new { action = "/Directory/User_Update", method = "POST" })
.Layout("grid")
.Grid(g => g.Cols(12).Gutter(20))
.Items(i =>
{
i.Add().Field(e => e.DepartmentId).Label("Отдел").Editor(e => e.DropDownList()
.DataTextField("Name")
.DataValueField("Id")
.DataSource(s =>
{
s.Read(r => r.Action("GetDepartments", "Home"));
}));
}))
When I comment form code, it runs without errors.
User:
public class User : Entity
{
public int? DepartmentId { get; set; }
public Department Department { get; set; }
}
Department:
public class Department : Entity
{
public virtual List<User> Users { get; set; }
}
Startup:
services.AddControllers().AddNewtonsoftJson(options =>
{
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
});
Endpoint which returns view:
[HttpGet("[controller]/User/{Id:int}")]
public async Task<IActionResult> UserView(int id)
{
var entity = await _userObjectService.GetAll()
.Include(e => e.Department)
.Where(e => e.Id == id)
.FirstOrDefaultAsync();
return View("User", entity);
}
Telerik version - 2022.1.301.