我有一个包含逗号的小数自定义模型绑定器,它基于这篇关于模型绑定十进制值的文章
这工作正常,除非由 ajax 请求使用
它适用于不包含带逗号的金额(即值小于一千)的 ajax 请求
错误是
System.ArgumentException: The parameters dictionary contains a null entry for parameter 'amount'
of non-nullable type 'System.Decimal' for method
'System.Web.Mvc.JsonResult IsDepositRequired(System.String, System.String, System.String,
Boolean, System.Decimal, System.DateTime)' in 'Client.Controllers.DealingController'. An
optional parameter must be a reference type, a nullable type, or be declared as an
optional parameter.
Parameter name: parameters
at System.Web.Mvc.ActionDescriptor.
ExtractParameterFromDictionary(ParameterInfo parameterInfo, IDictionary`2 parameters, MethodInfo methodInfo)
模型绑定器在 gobal.asax 中正确注册
知道我可能错过了什么谢谢
阿贾克斯代码:
$.post('/Dealing/IsDepositRequired', {
baseCurrency: deal.baseCurrency,
termsCurrency: deal.termsCurrency,
dealtCurrency: deal.dealtCurrency,
isBuy: deal.direction == 'BUY',
amount: deal.dealtCurrency == deal.baseCurrency ? deal.baseAmount : deal.termsAmount,
valueDate: deal.valueDate
}, function (show) {
if (show) {
$('.Deposit').fadeIn(500);
} else {
$('.Deposit').hide();
}
}, 'json');
控制器
[HttpPost]
public virtual JsonResult IsDepositRequired(string baseCurrency, string termsCurrency, string dealtCurrency, bool isBuy, decimal amount, DateTime valueDate)
{
Firebug 网络控制台:
amount 100,000.00
baseCurrency GBP
dealtCurrency GBP
isBuy true
termsCurrency EUR
valueDate 30/10/2012
资源:
baseCurrency=GBP&termsCurrency=EUR&dealtCurrency=GBP&isBuy=true&amount=100%2C000.00&valueDate=30%2F10%2F2012