I am working on .Net 5 Web API and I am using Swashbuckle
, when I used [JsonIgnore]
on my model it works fine for rendering my JSON
Model :
public partial class ApplicationDocument : BaseModel
{
public int id { get; set; }
public int document_id { get; set; }
public int application_id { get; set; }
[NotMapped]
public string name { get; set; }
[NotMapped]
public string documentUrl { get; set; }
[JsonIgnore]
public virtual Application application { get; set; }
[JsonIgnore]
public virtual Document document { get; set; }
}
JSON
{
"applicationDocument": {
"dateCreated": "2021-05-17T13:08:08.934Z",
"dateModified": "2021-05-17T13:08:08.934Z",
"createdBy": "string",
"modifiedBy": "string",
"isActive": true,
"isDeleted": true,
"id": 0,
"document_id": 0,
"application_id": 0,
"name": "string",
"documentUrl": "string"
},
"fileDocument": "string"
}
the problem is when I used the [FromForm]
attribute with my controller, the [JsonIgnore] didn't work for me and it rendered every single field even the navigation fields
Controller
[HttpPost]
[Route("[controller]/AddApplicationDocument")]
public BaseResponse AddApplicationDocument([FromForm] ApplicationDocumentViewModel ApplicationDocumentViewModel)
{
return _ApplicationDocument.AddApplicationDocument(ApplicationDocumentViewModel);
}