【发布时间】:2015-06-30 07:41:29
【问题描述】:
我需要在我的 web api 控制器中实现验证。 在我的课堂上,我有一个这样的方法:
public MyEntity Post(MyEntity entity)
{
// ...
}
在 POST 和 PUT 方法中,我通常返回创建/更新的对象。
在this tutoral 中,他们返回HttpResponseMessage,以便他们可以执行以下操作:
if (ModelState.IsValid)
{
// Do something with the product (not shown).
return new HttpResponseMessage(HttpStatusCode.OK);
}
else
{
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
}
有没有办法使用类似的方法返回保存的实体?
【问题讨论】:
-
好问题,但是标题和第一行表明它与验证有关。我不明白怎么做?
标签: c# .net asp.net-mvc asp.net-web-api