jquery - ASP.NET MVC 4 routing corrupting a decimal json value -
i have method in controller:
[httppost] public virtual jsonresult add(additemmodel request)
this receives ajax call. json request sends serialized version of "additemmodel" class , mvc routing creates additemmodel expected properties (which include datatypes such strings, integers , decimals).
i deploy our qa server , behaviour different. json request identical (checked fiddler) additemmodel has properties populated except decimal 1 - has value of 0 default value.
i can't find differences between our dev environment , qa server, i'm not looking @ right thing.
can suggest causing difference?
dev win7, qa win2003 server, running latest patches.
thanks in advance
griff
update #1
we added custom model binder both decimal , nullable decimal types , added tracing ascertain happening.
when value came in, picked attempted value:
var attvalue = modelbindingcontext.valueprovider .getvalue(modelbindingcontext.modelname).attemptedvalue;
and converted decimal value. tested base's bindmodel(controller, context) return.
for us, when attempted value '5', our conversion gave decimal value of 5. mvc code couldn't handle - returned '' object, arrives in our controller method zero.
however, when attempted value '5.1', both our , mvc code correctly gave decimal of 5.1.
so, appears when:
- json has value of : 5
- mvc attempts bind poco's property datatype decimal , fails
but when:
- json has value of : 5.1
- mvc attempts bind poco's property datatype decimal , works
as mentioned, happens on our qa server, not in dev. suggest microsoft may have fixed this? mentioned, appears both our dev , qa environs patched.
any suggestions here?
see this answer. in short, default model binder uses .net's type converter, cannot convert integers decimals.
Comments
Post a Comment