asp.net mvc - IgnoreDataMember attribute is skipping json object properties during **DE**serialization -
according docs, ignoredatamember attribute supposed considered during serialization.
from i'm seeing, however, mvc model binding using during *de*serialization of json well.
consider following class:
public class tax { public tax() { } public int id { get; set; } [required] [range(1, int.maxvalue)] [ignoredatamember] public int propertyid { get; set; } } if post/put following json string action method:
{"position":0,"description":"state sales tax","rate":5,"rateispercent":true,"propertyid":1912} i following validation error:
{ "message": "the request invalid.", "modelstate": { "newtax.propertyid": [ "the field propertyid must between 1 , 2147483647." ] } } both [range(1, int.maxvalue)] , [required] attributes invalid.
if remove [ignoredatamember] attribute, works fine.
is there different attribute can used tell mvc binding not ignore property during deserialization?
this happens when posting json string. if post name/value string, everthing works fine.
the answer has behavior of json.net. that's model binding using , it's checking ignoredatamember both serialization , deserialization making useless me (since want use serialization).
the jsonignore attribute works same way.
given that, pulled ignore attributes off properties , switched using json.net's conditional serialization methods.
so add above propertyid field:
public bool shouldserializepropertyid() { return false; } that allows deserialization come in blocks serialization going out.
Comments
Post a Comment