Did you find a solution? I have a similar problem. Can you help? I’ve tried several responses, but nothing seems to be working for me. ———————————————————————————————–
rachad is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
[JsonObject(IsReference = false)]
public class Demande
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[Display(Name = "Titre")]
public string? Titre { get; set; }
[Display(Name = "Description")]
public string? Description { get; set; }
[Required(ErrorMessage = "Le champ Date de création est requis.")]
[Display(Name = "Date de création")]
[DataType(DataType.DateTime)]
public DateTime DateCreation { get; set; }
[EnumDataType(typeof(Status))]
public Status Status { get; set; }
public string? UserI { get; set; }
public ApplicationUser? User { get; set; }
}
[JsonObject(IsReference = false)]
public class User
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public string? UserId { get; set; }
public string? Name { get; set; }
[EmailAddress]
[DataType(DataType.EmailAddress)]
public string? Email { get; set; }
[Required]
[DataType(DataType.Password)]
public string? Password { get; set; }
[DataType(DataType.Password)]
[Compare(nameof(Password))]
public string? ConfirmPassword { get; set; }
public Roles Role { get; set; }
public ICollection<Demande>? Demandes { get; set; }
}
builder.Services.AddControllers().AddJsonOptions((options =>
{
options.JsonSerializerOptions.ReferenceHandler = System.Text.Json.Serialization.ReferenceHandler.IgnoreCycles;}))
Result :::
Response body
Download
{
“$id”: “1”,
“$values”: []
}
rachad is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1