2014-02-09 20 views
1

我在extjs模型中有一個浮點值。出於某種原因,我輸入並傳遞給C#控制器的任何值,其值始終爲空。我檢查了正在傳遞的json數據,我可以看到傳入的值。Extjs浮點值被傳遞爲空的c#控制器

這是我的ExtJS的模型

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

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傳遞給控制器​​

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

在C#調試 '的floatValue' 的值總是空。

在這裏有什麼,我失蹤了。

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#

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

你可以從等式中消除extjs。這幾乎肯定是後端代碼的問題。如果您查看瀏覽器的網絡選項卡並查看有效負載正在正確發送,請關注C# –

+0

謝謝Matt。我檢查了請求負載並查看了數據。在c#上,除了FloatValue之外,所有其他數據都在那裏。我是否必須以某種方式定義浮點值才能正確映射它? – EagleFox

+1

我很久沒有使用ASP.NET MVC,所以我不是最好的幫助。但是,如果顯示更多代碼,則會獲得更多幫助。 EmployeeRecord如何被使用?控制器是什麼樣的? –

回答

0

這樣的行爲可以出現在溴代吸氣劑或setter錯誤。你可以給予制定者正確的值,但是如果它設置得不好,或者吸取器之後得到的東西比寫入的東西還要多,你可以很容易地看到這個值。

最有可能的吸氣劑或二道過濾器根本不會做它的工作。