2
我需要創建一個終點,但是這個終點可以有多種類型的輸入,表單本身可以根據配置進行更改,所以我試圖創建至少2個對象投入。WebApi模型綁定w/2個不同的對象
喜歡的東西:
public class ParticipationsController : ApiController
{
public HttpResponseMessage Post([FromBody]Models.SimpleParticipationModel sModel, [FromBody]Models.CompleteParticipationModel cModel)
{
if (!ModelState.IsValid) // this might not be this way here
{
return Request.CreateResponse(HttpStatusCode.BadRequest);
}
return Request.CreateResponse(HttpStatusCode.OK, "Ok");
}
我的觀點是,以避免多個終端和改變了很多renderization的頁面。
我的對象包含符合某些規則的DataAnotations,如「Required」和「Range 0-X」。
我也沒有什麼有一個對象的所有屬性,只履行其中的一些。
在此先感謝