將值發佈到其中一個參數是可爲空的int的控制器方法時遇到了一個錯誤。 重現步驟:從請求參數到方法參數綁定的ASP.NET MVC3 RC2缺陷
我已經創建了一個測試方法
[HttpPost]
public ActionResult PostTest(string from, int? number, bool? formsearch)
{
return new ContentResult { Content = string.Format("{0}/{1}/{2}", from, number, formsearch) };
}
使用jquery,創建一個POST請求
$.post("http://localhost/mysite/test/posttest",{ from:"1//1/2009",number:"156",formsearch:true});
請求清楚地示出的值(例如,在提琴手。)正在發送:
from:1 // 1/2009 number:156 formsearch:true
但是從這個函數返回的結果是:
1 //二千○九分之一//真
如果我改變INT?數爲int數量,其結果是正確的:
1 // 1/2009/156 /真
在MVC3 RC1這是沒有任何問題的工作與可空INT
更新:我不t似乎對新創建的MVC3網站有問題。我的項目中有什麼影響模型綁定到可空int的?爲什麼RC1和RC2會有區別?任何人都有建議調試這個模型綁定問題?
難道你不能只更新網站到MVC3 RTM? – 2012-03-01 13:03:33