我有一个用户信息表单,我用kendo控制器动态创建一些元素(组合框,日期表等)
我可以成功创建它们但是当我可以从datepicker获取所选项目组合框的值或所选日期的值时,它会返回给我空字符串。
这是我的观看页面:
@(Html.Kendo().ComboBox()
.AutoBind(false)
.Name("cmb"+number)
.HtmlAttributes(new { style = "width: 150px;" })
.DataTextField("myText")
.DataValueField("myId")
.DataSource(binding => binding.Read(read =>
{
read.Action("SetOptions", "List", new { id = number});
}))
)
@(Html.Kendo().DatePicker()
.Name("lyldt"+number).Format("yyyy-MM-dd")
)
使用这种格式我可以创建控件,但我无法获得控件的价值
这是SetOptions函数返回
List<ComboClasses> list = new List<ComboClasses>();
ComboClasses c = new ComboClasses();
list.Add(new ComboClasses()
{
myText = "Married",
myId = 1
});
list.Add(new ComboClasses()
{
myText = "Single",
myId = 2
});
return Json(list, JsonRequestBehavior.AllowGet);
这是我的javascript代码:
function CreateLoyaltyCard() {
var card = $("#cmbLoyaltyCards").data("kendoComboBox").value();
var cardt = $("#cmbLoyaltyCardsTypes").data("kendoComboBox").value();
var name = $("#lyltxtname").val();
var surname = $("#lyltxtsname").val();
var table = document.getElementById('tblLoyalty');
var rowLength = table.rows.length;
var dict = {
loyalty: []
};
for (var i = 4; i < rowLength; i += 1) {
if (i != rowLength - 1) {
var row = table.rows[i];
var mandatory = false;
var cellLength = row.cells.length;
for (var y = 0; y < cellLength; y += 1) {
if (y == 0) {
var cell = row.cells[0];
var celtext = cell.textContent.toString();
var div = celtext.indexOf("*");
if (div >= 0) {
mandatory = true;
}
}
if (y == 2) {
var cell = row.cells[2];
var tip = cell.children[1].textContent;
var number = cell.children[2].textContent;
if (tip == "text") {
var myval;
if (mandatory) {
myval = cell.children[0].value;
dict.loyalty.push({
"number": number,
"tip": tip,
"mvalue": myval
});
if (myval == null || myval == "") {
$('#lblMessageLoyalty').text("Please Fill all mandatory fields");
$('#LoyaltyOKWindow').data('kendoWindow').center().open().refresh();
return;
}
}
else {
myval = cell.children[0].value;
var myArr = [number, tip, myval];
dict.loyalty.push({
"number": number,
"tip": tip,
"mvalue": myval
});
}
}
else if (tip == "select") {
var myselectval;
if (mandatory) {
myselectval = $("#cmb" + number).data("kendoComboBox").dataItem();
dict.loyalty.push({
"number": number,
"tip": tip,
"mvalue": myselectval
});
if (myselectval == null || myselectval == "") {
$('#lblMessageLoyalty').text("Please Fill all mandatory fields");
$('#LoyaltyOKWindow').data('kendoWindow').center().open().refresh();
return;
}
}
else {
myselectval = $("#cmb" + number).data("kendoComboBox").value();
dict.loyalty.push({
"number": number,
"tip": tip,
"mvalue": myselectval
});
}
}
else if (tip == "date") {
if (mandatory) {
var datepicker = $('#lyldt' + number).data('kendoDatePicker');
datepicker = kendo.toString(datepicker.value(), 'yyyyMMdd');
dict.loyalty.push({
"number": number,
"tip": tip,
"mvalue": datepicker
});
if (datepicker == null || datepicker == "") {
$('#lblMessageLoyalty').text("Please Fill all mandatory fields");
$('#LoyaltyOKWindow').data('kendoWindow').center().open().refresh();
return;
}
}
else {
var datepicker = $('#lyldt' + number).data('kendoDatePicker');
datepicker = kendo.toString(datepicker.value(), 'yyyyMMdd');
dict.loyalty.push({
"number": number,
"tip": tip,
"mvalue": datepicker
});
}
}
else if (tip == "numeric") {
var mynumval;
if (mandatory) {
mynumval = cell.children[0].value;
dict.loyalty.push({
"number": number,
"tip": tip,
"mvalue": mynumval
});
if (mynumval == null || mynumval == "") {
$('#lblMessageLoyalty').text("Please Fill all mandatory fields");
$('#LoyaltyOKWindow').data('kendoWindow').center().open().refresh();
return;
}
}
else {
mynumval = cell.children[0].value;
dict.loyalty.push({
"number": number,
"tip": tip,
"mvalue": mynumval
});
}
}
}
}
}
}
你知道吗?为什么这样做或我错过了什么?
谢谢