У меня есть класс DTO, как
[DataContract]
public class MyDTO
{
[DataMember(IsRequired)]
public string MyProperty { get; set; }
}
Когда я делаю запрос POST
без MyProperty
, я не получаю никаких исключений.
EDIT:
Мой контроллер выглядит так:
[HttpPost]
public async Task<IActionResult> Add([FromForm] MyDTO newDTO)
{
if (!this.ModelState.IsValid)
{
var errors = this.GetModelStateErrors();
return this.BadRequest();
}
try
{
var newDo = this.mapper.Map<MYDTO, MyDO>(newDto);
await this.dataManager.InsertAsync(this.myDbContext, newDo);
return this.StatusCode(201);
}
catch (ValidationException e)
{
return this.BadRequest(e.Message);
}
catch (Exception e)
{
return this.StatusCode(500, "Unspecified error occurred while processing request.");
}
}
Я также проверяю DO в контексте Db. Я хотел бы проверить DTO.