我有包含這是基於這個 文章關於Model Binding Decimal Values模型綁定請求
這個工程使用時通過一個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)
模型綁定在golbal.asax正確註冊
任何想法,我可以錯過 感謝
Ajax代碼:
$.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)
{
螢火蟲網控制檯:
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
將使用模型聯編程序 - 您可能無法正確創建您的AJAX請求。你有沒有嘗試過使用Fiddler或類似的東西來查看實際的請求? – Simon 2012-04-17 13:57:21
你能發佈你的AJAX代碼嗎? – 2012-04-17 13:59:00
我添加了以上代碼 – ChrisCa 2012-04-17 14:32:23