从传递JSON可空十进制到ASP.NET MVC控制器动作? [英] Passing nullable decimal from json to ASP.NET MVC Controller Action?

查看:122
本文介绍了从传递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控制器动作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆