如何将 DateTimePicker 值从 VIew 传递给控制器?
How to Pass DateTimePicker Value to Controller from VIew?
我想将 datetimepicker 值传输到我的控制器。我可以通过常规方式转移价值:
//PassDate Value While Calling Main Controller.
vrdCurv = "@Url.Action("GetOutgoingMessage", "OutGoingMessages", new { ABC = "asdnfsdf" })";
但是无法从下面的代码中得到结果。
//******Start of Date Pickers************
var datepickerFrom = $("#dateFromPicker").kendoDatePicker({
format: "dd/MM/yyyy",
change: function () {
datepickerTo.min(datepickerFrom.value());
},
}).data("kendoDatePicker");
//PassDate Value While Calling Main Controller.
vrdCurv = "@Url.Action("GetOutgoingMessage", "OutGoingMessages", new { dateTimePicker.value })";
//控制器代码:
[HttpGet]
public JsonResult GetOutgoingMessage(string ABC)
{
var a = abc;
}
我还尝试通过以下代码传递普通变量值,但该代码也不起作用:
[HttpGet]
public JsonResult GetOutgoingMessage(DateTime? abc)
{
using (var db = SiteUtil.NewDb)
{
TempData["msg"] = abc;
}
}
//Jscript:
var fromDate = null;
var toDate = null;
//Inilialise date variable.
fromDate = '2015-07-10';
toDate = '2015-07-10';
var dataSourceOutMessage = new kendo.data.DataSource({
transport: {
read: {
url: "@Url.Action("GetOutgoingMessage", "OutGoingMessages")",
dataType: 'json',
date:{"fromdate" : fromdate}
}
},
schema: {
model: {
fields:
{
Id: { type: "String" },
MsgType: { type: "String" },
Subject: { type: "String" },
CreatedOn: { type: "String" },
ProcessedOn: {type: "date"}
}
}
},
pageSize: 20
});
你能试试这个吗:
vrdCurv = "@Url.Action("GetOutgoingMessage", "OutGoingMessages", new { ABC = "-1"})";
vrdCurv.replace("-1", datepickerFrom.value());
(脏但我认为这会起作用)
我强烈建议您从头开始学习 ASP.NET MVC here。
我想将 datetimepicker 值传输到我的控制器。我可以通过常规方式转移价值:
//PassDate Value While Calling Main Controller.
vrdCurv = "@Url.Action("GetOutgoingMessage", "OutGoingMessages", new { ABC = "asdnfsdf" })";
但是无法从下面的代码中得到结果。
//******Start of Date Pickers************
var datepickerFrom = $("#dateFromPicker").kendoDatePicker({
format: "dd/MM/yyyy",
change: function () {
datepickerTo.min(datepickerFrom.value());
},
}).data("kendoDatePicker");
//PassDate Value While Calling Main Controller.
vrdCurv = "@Url.Action("GetOutgoingMessage", "OutGoingMessages", new { dateTimePicker.value })";
//控制器代码:
[HttpGet]
public JsonResult GetOutgoingMessage(string ABC)
{
var a = abc;
}
我还尝试通过以下代码传递普通变量值,但该代码也不起作用:
[HttpGet]
public JsonResult GetOutgoingMessage(DateTime? abc)
{
using (var db = SiteUtil.NewDb)
{
TempData["msg"] = abc;
}
}
//Jscript:
var fromDate = null;
var toDate = null;
//Inilialise date variable.
fromDate = '2015-07-10';
toDate = '2015-07-10';
var dataSourceOutMessage = new kendo.data.DataSource({
transport: {
read: {
url: "@Url.Action("GetOutgoingMessage", "OutGoingMessages")",
dataType: 'json',
date:{"fromdate" : fromdate}
}
},
schema: {
model: {
fields:
{
Id: { type: "String" },
MsgType: { type: "String" },
Subject: { type: "String" },
CreatedOn: { type: "String" },
ProcessedOn: {type: "date"}
}
}
},
pageSize: 20
});
你能试试这个吗:
vrdCurv = "@Url.Action("GetOutgoingMessage", "OutGoingMessages", new { ABC = "-1"})";
vrdCurv.replace("-1", datepickerFrom.value());
(脏但我认为这会起作用)
我强烈建议您从头开始学习 ASP.NET MVC here。