本文介绍了从传递JSON可空十进制到ASP.NET MVC控制器动作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个接收DTO又包含可为空小数属性的Asp.NET MVC控制器动作。
I have an Asp.NET MVC controller action which receives a DTO which in turn contains a nullable decimal property.
例如
[DataContact] public class MyDTO { //other properties [DataMember] public decimal? SomeProp {get;set;} }和我的行动看起来像这样:
and my action looks like this:
public JsonResult SaveMyDTO(MyDTO dto) {...我可以看到JS客户传递正确的JSON数据,也有SomeProp设置值然而,在服务器上反序列化时,该属性没有设置,其他属性,但不是为空的小数道具。
I can see that the js client passes the correct json data, there are values set for "SomeProp" however, the property is not set when deserialized on the server, other properties are, but not the nullable decimal prop.
什么是使它工作的最简单的方法?财产转换为字符串?
What is the easiest way to make it work? convert the property to string?
推荐答案更改属性为空的双重使它正常工作。
Changing the property to nullable double makes it work correctly.
更多推荐
从传递JSON可空十进制到ASP.NET MVC控制器动作?
发布评论