在javascript中向操作发送日期
我有一个日期选择器,我需要获取一个日期并将该日期传递给控制器。到目前为止,我有以下代码: JavaScript函数:在javascript中向操作发送日期,javascript,c#,datepicker,Javascript,C#,Datepicker,我有一个日期选择器,我需要获取一个日期并将该日期传递给控制器。到目前为止,我有以下代码: JavaScript函数: $(function () { intDate = Date; $("#datepicker").datepicker({ onClose: function (select_date) { //console.log(select_date); var date = $('#datepicker').val();
$(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");
}
型号:
$(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");
}
public IEnumerable getInfoByDate(日期时间日期)
{
CareDB上下文=新的CareDB();
SqlParameter日期=新的SqlParameter(“@Date”,日期);
对象[]参数=新对象[]{Date};
IEnumerable lst=context.ReleaseDate.SqlQuery(“\u UserInformationByDate@Date”,parameters).ToList();
context.Dispose();
上下文=空;
返回lst;
}
控制器:
$(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");
}
public ActionResult EmployeeDate(mvcapapplication1.Models.DateTime日期)
{
Models.BL oBL=新Models.BL();
IEnumerable lstEmployees=oBL.getInfoByDate(日期);
ViewBag.DataSource=lstEmployees;
返回视图(“员工信息”);
}
当我尝试执行该函数时,会收到以下消息:
jquery-1.10.2.js:8706 GET 404(未找到)
然后当然会说这是一个错误
我认为问题在于日期的格式,因为正如你所看到的,它的格式很奇怪。。有什么想法吗
任何帮助都将不胜感激!谢谢 您正在向
GetUserInfoDate
发送请求,但是您的控制器名称是getInfoByDate
您需要如下更改代码:
$(function () {
intDate = Date;
$("#datepicker").datepicker({
onClose: function (select_date) {
//console.log(select_date);
var date = $('#datepicker').val();
console.log(date.toString());
$.ajax('/Home/getInfoByDate', {
data: {
date: 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);
}
});
})) 您正在向
GetUserInfoDate
发送请求,但是您的控制器名称是getInfoByDate
您需要如下更改代码:
$(function () {
intDate = Date;
$("#datepicker").datepicker({
onClose: function (select_date) {
//console.log(select_date);
var date = $('#datepicker').val();
console.log(date.toString());
$.ajax('/Home/getInfoByDate', {
data: {
date: 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);
}
});
})) 日期格式看起来没有问题。404表示请求的
http://localhost:51299/Home/GetUserInfoDate
找不到位置。日期格式似乎没有问题。404表示请求的http://localhost:51299/Home/GetUserInfoDate
找不到位置。