从传递JSON可空十进制到ASP.NET MVC控制器动作?

编程入门 行业动态 更新时间:2024-10-12 03:23:38
本文介绍了从传递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控制器动作?

本文发布于:2023-11-24 19:57:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1626606.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控制器   动作   可空十进制到   JSON   ASP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!