c# - ASP.NET Web API ModelState do not contains all parameters, validation do not work -
i'm using asp.net web api , have post method in controller:
[route("order/{siteid}/{orderid}")] public httpresponsemessage post(long siteid, long orderid, orderinformation orderinfo) { if (modelstate.isvalid) { ... } }
i have couple info annotations in orderinformation class (required etc.) unfortunately validation not work. because modelstate not contains key orderinfo. contains siteid , orderid.
so question why orderinfo parameter not included in modelstate. have not thought why works weird because utilize similar code on different places , works fine.
edit:
here model (orderinformation class):
public class torderinformation { [required] public string loyaltynumber; [required] public string specialinstructions; public bool sendemail; ... // few more string properties, no info annotations }
edit 2:
i'm sending complex type in body serialized json. tried signature of method:
[route("order/{siteid}/{orderid}")] public httpresponsemessage post(long siteid, long orderid, [frombody] orderinformation orderinfo)
uff found problem. there can't public fields in model, must properties.
c# asp.net asp.net-mvc asp.net-web-api web-api
No comments:
Post a Comment