这是我的 POST 操作ApiController
。
public HttpResponseMessage Post(ViewModel model)
{
if (!ModelState.IsValid)
{
var ResponseMessage = new HttpResponseMessage(HttpStatusCode.XXXXXX
return ResponseMessage;
}
if (!_service.Create(model))
{
var ResponseMessage=new HttpResponseMessage(HttpStatusCode.NotAcceptable);
return ResponseMessage;
}
else
{
return new HttpResponseMessage(HttpStatusCode.Created);
}
}
这样启用服务端模型验证可以吗?而且,如果一切正常,我很确定Created
应该返回 a 。但是如果 ModelState 无效,或者发生错误,我应该返回什么样的 HttpStatusCode 呢?