我需要在我的web api控制器中实现验证。 在我的班上,我有一个这样的方法:
<meta name="apple-mobile-web-app-capable" content="no">
在POST和PUT方法中,我通常返回创建/更新的对象。
在this tutoral中,他们返回public MyEntity Post(MyEntity entity)
{
// ...
}
,以便他们可以执行以下操作:
HttpResponseMessage
有没有办法使用类似的方法返回已保存的实体?
答案 0 :(得分:2)
您应该使用HttpRequestMessageExtensions.CreateResponse方法。例如:
if (ModelState.IsValid)
{
// Do something with the product (not shown).
return Request.CreateResponse<MyEntity>(HttpStatusCode.OK, entity);
}