添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

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.

Hello kva,

Thank you for applying code snippets.

However it is difficult for me to understand the full context of the behavior experienced on your side.

Could you please share additional details in regard to the experienced behavior like:

  • the circumstances in which the error occurs;
  • the full error code;
  • the full configuration of the shared files;

These or ideally an isolated sample project that showcases the behavior will enable me to investigate the issue in depth and suggest a possible solution.

Thank you for your cooperation in advance.

Regards,
Stoyan
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages. If you're new to the Telerik family, be sure to check out our getting started resources, as well as the only REPL playground for creating, saving, running, and sharing server-side code.

Hello Kva,

I noticed you have updated your initial message with additional relevant information and snippets.

This allowed me to continue investigating the issue.
 
So far I wasn't able to reproduce the behavior on my side by using the shared snipepts. This leads me to suspect the issue is arises outside of Telerik UI for ASP.NET Core.

Here is what I recommend to resolve the behavior, if possible try replacing the NewtonSoft.Json Serializer with the AddJsonOptions built into the Microsoft.Extensions.DependencyInjection.

Alternatively, explore the suggestions in the related StackOverflow thread JSON.Net Self referencing loop detected.

If you find that I am missing something in the reproduction, please share more information on the topic or ideally, consider sharing an isolated sample project that showcases the reported behavior.

Regards,
Stoyan.