我想將datetimepicker值傳輸到我的控制器。我可以通過常規轉移價值:如何將DateTimePicker值傳遞給來自VIew的控制器?
//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
});
'@ Url.Action()'是在服務器發送到視圖之前在服務器上評估的剃鬚刀代碼。你不能使用'new {dateTimePicker.value}' - 因爲'dateTimePicker'在服務器上不存在。您需要使用ajax發佈值 –
我試圖傳遞也不起作用的普通變量。 –
你需要顯示你已經試過的代碼 –