我有一個日期選擇器,我需要得到一個日期並將該日期傳遞給控制器。到目前爲止,我有以下代碼:發送日期到javascript中的動作
JavaScript函數:
$(function() {
intDate = Date;
$("#datepicker").datepicker({
onClose: function (select_date) {
//console.log(select_date);
var date = $('#datepicker').val();
console.log(date.toString());
$.ajax('/Home/GetUserInfoDate', {
data: {
intDate: date
},
success: function (data, textStatus, jqXHR) {
//this will happen on success of request
$('#divData').html(data);
},
error: function() {
console.log("error handler when ajax request fails... ");
},
});
//console.log(date);
}
});
});
型號:
public IEnumerable<DateTime> getInfoByDate(DateTime date)
{
CareDB context = new CareDB();
SqlParameter Date = new SqlParameter("@Date", date);
object[] parameters = new object[] { Date };
IEnumerable<DateTime> lst = context.ReleaseDate.SqlQuery("_UserInformationByDate @Date", parameters).ToList();
context.Dispose();
context = null;
return lst;
}
控制器:
public ActionResult EmployeeDate(MvcApplication1.Models.DateTime date)
{
Models.BL oBL = new Models.BL();
IEnumerable<MvcApplication1.Models.DateTime> lstEmployees = oBL.getInfoByDate(date);
ViewBag.DataSource = lstEmployees;
return View("EmployeeInformation");
}
當我試圖執行的功能我得到這個消息:
jQuery的1.10.2.js:8706 GET http://localhost:51299/Home/GetUserInfoDate?intDate=05%2F03%2F2016 404(未找到)
然後當然,說這是一個錯誤。
我認爲問題是與日期的格式,因爲你可以看到它有一個奇怪的格式..任何想法?
任何幫助將不勝感激!謝謝!
它看起來不像日期格式的問題。 404意味着未找到請求的「http:// localhost:51299/Home/GetUserInfoDate」位置。 – RRK