Jquery 未使用Kendo UI Web日期选择器值更新模型
我在Visual Studio 2012中有一个MVC Razor项目,正在使用Kendo UI Web HTML控件。我有一个通过弹出窗口编辑的网格。当我编辑一条记录时,除了两个日期选择器之外,所有控件的值都会更新我的模型。在Firebug中,我可以看到日期值以“2013年5月14日星期二00:00:00 GMT+1000(澳大利亚东部标准时间)”的格式发布,但发送到数据源的传输:更新函数(UpdateRegisterEntry)的模型的这些字段为空。有人能帮我吗?以下是相关代码: _Layout.cshtmlJquery 未使用Kendo UI Web日期选择器值更新模型,jquery,asp.net-mvc,razor,datepicker,kendo-ui,Jquery,Asp.net Mvc,Razor,Datepicker,Kendo Ui,我在Visual Studio 2012中有一个MVC Razor项目,正在使用Kendo UI Web HTML控件。我有一个通过弹出窗口编辑的网格。当我编辑一条记录时,除了两个日期选择器之外,所有控件的值都会更新我的模型。在Firebug中,我可以看到日期值以“2013年5月14日星期二00:00:00 GMT+1000(澳大利亚东部标准时间)”的格式发布,但发送到数据源的传输:更新函数(UpdateRegisterEntry)的模型的这些字段为空。有人能帮我吗?以下是相关代码: _Layo
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>@ViewBag.Title - My ASP.NET MVC Application</title>
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<meta name="viewport" content="width=device-width" />
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
<script src="@Url.Content("~/Scripts/EditorHookup.js")" type="text/javascript"></script>
<!-- Common Kendo UI Web CSS -->
<link href="~/Content/kendo/2013.1.319/kendo.common.min.css" rel="stylesheet" />
<!-- Default Kendo UI Web theme CSS -->
<link href="~/Content/kendo/2013.1.319/kendo.default.min.css" rel="stylesheet" />
<!-- jQuery JavaScript -->
<script src="~/Scripts/jquery-1.9.1.min.js"></script>
<!-- Kendo UI Web combined JavaScript -->
<script src="~/Scripts/kendo/2013.1.319/kendo.web.min.js"></script>
<script src="~/Scripts/kendo/2013.1.319/cultures/kendo.culture.en-AU.min.js"></script>
<script type="text/javascript">
//set the Kendo UI culture
kendo.culture("en-AU");
</script>
</head>
<body>
<div id="body">@RenderSection("featured", required: false)
<section class="content-wrapper main-content clear-fix">@RenderBody()
</section>
<p class="content-wrapper">
<label style="color: Red; font-weight: bold; margin-left: 10px" id="lblStatus" runat="server">@ViewBag.Status</label>
</p>
</div>
<footer>
<div class="content-wrapper">
<div class="float-left">
<p>© @DateTime.Now.Year - FAI Register</p>
</div>
</div>
</footer>
@Scripts.Render("~/bundles/jquery")
@RenderSection("scripts", required: false)
</body>
</html>
日期时间编辑器模板
@model DateTime?
@Html.TextBox("", Model.GetValueOrDefault(), "dd/MM/yyyy", new
{
@class = "date",
style = ViewData["style"]
})
相关Javascript
var faistatuses = [];
function HookUpEditors()
{
//get fai statuses and rebind the grid
$.getJSON("api/register/statuses", function (data)
{
faistatuses = data;
});
$(".date").kendoDatePicker({
value: new Date(),
min: new Date(1950, 0, 1),
max: new Date(2049, 11, 31),
culture: "en-AU",
format: "dd/MM/yyyy",
parseFormats: ["dd/MM/yyyy"]
});
$(".currency").kendoNumericTextBox({
format: "c2"
});
$(".decimal").kendoNumericTextBox({
format: "n0",
min: 0
});
$(".percentage").kendoNumericTextBox({
format: "p0"
});
$(".faistatuses").kendoDropDownList({
dataTextField: "RegistryStatusName",
dataValueField: "Id",
dataSource: faistatuses
});}
}
我已经想出了解决这个问题的办法。我需要重新格式化日期,这样json和rest服务就可以了 在剑道ui数据源的参数映射函数中,我执行以下操作:
parameterMap: function (data, type)
{
if ( type != "read")
{
data.DateField = fixDateFormat(data.DateField);
}
}
function fixDateFormat(date)
{
var formatted;
if (date != null)
{
formatted = date.getFullYear() + "-" +
("0" + (date.getMonth() + 1)).slice(-2) + "-" +
("0" + date.getDate()).slice(-2);
}
return formatted;
}
希望这是清楚的,可以帮助其他人。有人能帮忙吗?Telerik?
@model DateTime?
@Html.TextBox("", Model.GetValueOrDefault(), "dd/MM/yyyy", new
{
@class = "date",
style = ViewData["style"]
})
var faistatuses = [];
function HookUpEditors()
{
//get fai statuses and rebind the grid
$.getJSON("api/register/statuses", function (data)
{
faistatuses = data;
});
$(".date").kendoDatePicker({
value: new Date(),
min: new Date(1950, 0, 1),
max: new Date(2049, 11, 31),
culture: "en-AU",
format: "dd/MM/yyyy",
parseFormats: ["dd/MM/yyyy"]
});
$(".currency").kendoNumericTextBox({
format: "c2"
});
$(".decimal").kendoNumericTextBox({
format: "n0",
min: 0
});
$(".percentage").kendoNumericTextBox({
format: "p0"
});
$(".faistatuses").kendoDropDownList({
dataTextField: "RegistryStatusName",
dataValueField: "Id",
dataSource: faistatuses
});}
}
parameterMap: function (data, type)
{
if ( type != "read")
{
data.DateField = fixDateFormat(data.DateField);
}
}
function fixDateFormat(date)
{
var formatted;
if (date != null)
{
formatted = date.getFullYear() + "-" +
("0" + (date.getMonth() + 1)).slice(-2) + "-" +
("0" + date.getDate()).slice(-2);
}
return formatted;
}