简体   繁体   English

Extjs浮点值在C#控制器中作为null传递

[英]Extjs float value is being passed as null in c# controller

I have a float value in extjs model. 我在extjs模型中有一个float值。 For some reason any value I enter and pass to c# controller, its value is always null. 由于某种原因,我输入并传递给c#控制器的任何值,其值始终为null。 I checked the json data being pass and I can see the passed value. 我检查了传递的json数据,可以看到传递的值。

This is my extjs model 这是我的extjs模型

fields: [
    { name: 'Id', type: 'int' },
    { name: 'FloatValue', type: 'float' },
    { name: 'RecId', type: 'int' },
    { name: 'Valid', type: 'bool' }
 ]

C# C#

public class EmployeeRecord
{
    public int Id { get; set; } 
    public double? FloatValue { get; set; }
    public int RecId { get; set; }
    public bool Valid { get; set; }
}

JsonObject passed to controller JsonObject传递给控制器

{ Id: 0, FloatValue: 0.1, RecId: 12, Valid: true }

On C# debug the value of 'FloatValue' is always null. 在C#调试中,“ FloatValue”的值始终为null。

Is there something here that I am missing. 这里有我想念的东西吗?

UPDATE - 更新-

var employee = new Object();
employee.Id = 0;
employee.FloatValue = 0.1;
employee.RecId = 12;
employee.Valid = true;

Ext.Ajax.request({
        method: 'POST',
        scope: this,
        url: 'EmployeeController/UpdateRecord',
        headers: { 'Content-Type': 'application/json' },
        dataType: 'json',
        jsonData: { employeeRec: employee },
        success: function (Response) {},
        failure: function () {}
});

C# C#

public static EmployeeRecord UpdateRecord(IList<EmployeeRecord> employeeRec)
    {
        //Here employeeRec.FloatValue is null but other property has their values.
    }

Such behavior can appear brom an error in the getter or setter. 这种行为可能会在getter或setter中出现错误。 You can give the correct valur to setter, but if it sets it badly, or getter afterwards gets something else than was written, you can easily see that null. 您可以将正确的评估器分配给setter,但是如果它对setter的设置不正确,或者之后的getter获得了不同于编写的其他东西,则可以轻松地看到null。

The most probably getter or setter simply won't do its work. 最有可能的getter或setter根本不会做它的工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM