我使用jQuery UI控件。
我有一个日期选择器,我检索如下日期:在DateTime中从jquery转换日期
var sDate = $("#startDatePicker").datepicker('getDate');
var eDate = $("#endDatePicker").datepicker('getDate');
其作为SDATE为例返回
Tue Aug 14 00:00:00 UTC+0200 2012
我所说的代码从网页如下
$.ajax(
{
url: '@Url.Action("LogsView","Home")',
type: 'POST',
data: { startDate: sDate, endDate: eDate },
success: function(result) { alert(result); },
error: function(param1) { alert(param1); }
});
我有一个控制器,有以下动作
public JsonResult LogsView(DateTime startDate, DateTime endDate)
{
var items = FetchItems(startDate, endDate);
return Json(items, JsonRequestBehavior.AllowGet);
}
当我运行它,返回的错误的部分如下(以小提琴手抢滩时):
The parameters dictionary contains a null entry for parameter 'startDate' of non-nullable type 'System.DateTime' for method 'System.Web.Mvc.JsonResult LogsView(System.DateTime, System.DateTime)' ..
我已经通过勾选发送小提琴手我PARAMS,它是如下startDate=&endDate=
任何人都知道如何格式化并正确传递日期(我认为这是错误所在)?
.toJSON为我工作,谢谢。 –