我有一个日期选择器,我需要得到一个日期并将该日期传递给控制器。到目前为止,我有以下代码:发送日期到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