小编San*_*mar的帖子

检测到不支持的可能的对象循环

我知道这里有关于那个特定问题的问答,但我的问题并不独特(我猜)。

这是我的模型类:

public class RoleMaster
{
    [Key]
    [Required]
    public int Id { get; set; }

    [Required]
    [StringLength(20)]        
    public string Role { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

这是我的控制器:

public class RolesController : ControllerBase
{
    private readonly IRolesRepository _repo;


    public RolesController(IRolesRepository repo)
    {
        _repo = repo;
    }


    [HttpGet]
    public IActionResult Get()
    {
        var roles = _repo.GetRoles();
        return new JsonResult(roles);
    }
}
Run Code Online (Sandbox Code Playgroud)

我的存储库:

public interface IRolesRepository
{
    Task<IEnumerable<RoleMaster>> GetRoles();
}
Run Code Online (Sandbox Code Playgroud)

这是 GetRoles 方法:

public async Task<IEnumerable<RoleMaster>> GetRoles()
    {
        try
        {
            var roles = await …
Run Code Online (Sandbox Code Playgroud)

.net c# jsonexception asp.net-core

0
推荐指数
1
解决办法
8140
查看次数

标签 统计

.net ×1

asp.net-core ×1

c# ×1

jsonexception ×1