jqueryuiコントロールを使用します。
私は日付ピッカーを持っていて、次のように日付を取得します。
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);
}
私がそれを実行すると、返されるエラーの一部は次のとおりです(フィドラーでviedした場合):
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)' ..
fiddler経由で送信されたパラメータを確認しました。次のとおりです。startDate=&endDate=
日付を正しくフォーマットして渡す方法を知っている人はいますか(これがエラーの原因だと思います)?