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.
}
你可以從等式中消除extjs。這幾乎肯定是後端代碼的問題。如果您查看瀏覽器的網絡選項卡並查看有效負載正在正確發送,請關注C# –
謝謝Matt。我檢查了請求負載並查看了數據。在c#上,除了FloatValue之外,所有其他數據都在那裏。我是否必須以某種方式定義浮點值才能正確映射它? – EagleFox
我很久沒有使用ASP.NET MVC,所以我不是最好的幫助。但是,如果顯示更多代碼,則會獲得更多幫助。 EmployeeRecord如何被使用?控制器是什麼樣的? –