我是使用kendo ui的MVC.NET应用程序的新手。我有一个视图,其中有一个剑道下拉列表和2个剑道网格。下拉将使用控制器从SQL DB检索值(计划/计划ID),并将默认值分配给控制器中的下拉列表。下拉的默认值将由Kendo网格(主要和次要)用于从SQL检索值(与所选计划关联的资源)。
问题:与页面加载时,与kendo网格关联的控制器未获得下拉列表的选定值。当我在控制台中记录选定的下拉值时,我看到空白值被记录(参见屏幕附件)。请让我知道我必须做些什么才能获得页面加载下拉值。感谢
我在下面提供了下拉菜单,网格和Javascript功能详情:
<div class="form-group">
@(Html.Kendo().DropDownList()
.Name("ddlBenefitPlans")
.HtmlAttributes(new { style = "width:360px" })
.DataTextField("Text")
.DataValueField("Value")
.AutoBind(true)
.SelectedIndex(1)
.DataSource(source =>
{
source.Read
(read =>
{
read.Action("GetBenefitPlans", "Home");
}
);
})
.Events(e => e.Change("OnBenefitPlanChange"))
)
</div>
&#13;
与Kendo网格相关联的操作方法需要传递三个参数。使用javascript函数传递数据。
<div>
@(Html.Kendo().Grid<Beneficiary.Areas.p.Models.IndividualList>()
.Name("primaryGrid")
.Scrollable(sc => sc.Height(140))
.Pageable()
.Scrollable()
.AutoBind(true)
.Events(x => x.DataBound("primaryGridDataBound"))
.Columns(column =>
{
column.Template(@<text><a class="btn btn-link btn-xs"></a></text>).
ClientTemplate("<a onclick=ShowModalDialog('#=PlanLinkID#')>Delete</a>").Title("Action");
column.Bound(p => p.FirstName).Title("Name");
//column.Bound(p => p.Distribute).Title("Percentage %");//.HtmlAttributes(new { style = "font-weight:bold;" }).Hidden( p => p.DistributeEven = 0);
column.Bound(p => p.Percentage)
.ClientTemplate("<input class='numeric' type='number' value='#= Percentage #' min='0' max='100' step='1' id='PrimaryPercentage_#=PlanLinkID#' name='PrimaryPercentage_#=PlanLinkID#'/><input id='PrimaryPercentageDispute_#=PlanLinkID#' name='PrimaryPercentageDispute_#=PlanLinkID#' visible='false' ReadOnly='true'/>");
column.Bound(p => p.Address).Title("Address");
column.Bound(p => p.RelationShip).Title("Relationship");
column.Bound(p => p.IndividualID).Visible(false);
column.Bound(p => p.DistributeEven).Visible(false);
})
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("IndividualList", "Home").Data("GetBenefitPlanAndPrimary"))
)
)
</div>
&#13;
<div>
@(Html.Kendo().Grid<Beneficiary.Areas.p.Models.IndividualList>()
.Name("secondaryGrid")
.Scrollable(sc => sc.Height(140))
.Pageable()
.Scrollable()
.AutoBind(true)
.Events(x => x.DataBound("secondaryGridDataBound"))
.Columns(column =>
{
column.Template(@<text><a class="btn btn-link btn-xs"></a></text>).
ClientTemplate("<a onclick=ShowModalDialog('#=PlanLinkID#')>Delete</a>").Title("Action");
column.Bound(p => p.FirstName).Title("Name");
//column.Bound(p => p.Distribute).Title("Percentage %").HtmlAttributes(new { style = "font-weight:bold;" }).Hidden(Model.DistributeEven != 0);
column.Bound(p => p.Percentage)
.ClientTemplate("<input class='numeric' type='number' value='#= Percentage #' min='0' max='100' step='1' id='SecondaryPercentage_#=PlanLinkID#' name='SecondaryPercentage_#=PlanLinkID#'/><input id='SecondaryPercentageDispute_#=PlanLinkID#' name='SecondaryPercentageDispute_#=PlanLinkID#' value='Dispute' visible='false' ReadOnly='true'/>");
column.Bound(p => p.Address).Title("Address");
column.Bound(p => p.RelationShip).Title("Relationship");
column.Bound(p => p.IndividualID).Visible(false);
column.Bound(p => p.DistributeEven).Visible(false);
})
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("IndividualList", "Home").Data("GetBenefitPlanAndSecondary"))
)
)
</div>
&#13;
function GetBenefitPlanAndPrimary() {
console.log($("#ddlBenefitPlans").data("kendoDropDownList").value());
return {
benefitPlanID: $("#ddlBenefitPlans").data("kendoDropDownList").value(),
isPrimOrSecondary: 1,
Masked: true,
};
}
function GetBenefitPlanAndSecondary() {
console.log($("#ddlBenefitPlans").data("kendoDropDownList").value());
return {
benefitPlanID: $("#ddlBenefitPlans").data("kendoDropDownList").value(),
isPrimOrSecondary: 3,
Masked: true,
};
}
&#13;
与下拉菜单相关的操作方法:
public JsonResult GetBenefitPlans([DataSourceRequest] DataSourceRequest request)
{
List<BenefitPlans> lBenefitPlans = beneficiaryBL.GetBenefitPlans();
List<SelectListItem> lstBenefitPlans = new List<SelectListItem>();
SelectListItem item = new SelectListItem();
item.Text = "Select"; item.Value = string.Empty;
lstBenefitPlans.Add(item);
Boolean isItemSelected = false;
foreach (BenefitPlans p in lBenefitPlans)
{
item = new SelectListItem() { Text = p.BenefitPlan, Value = p.ID.ToString() };
if (!isItemSelected)
{
item.Selected = true;
isItemSelected = true;
}
lstBenefitPlans.Add(item);
}
lstBenefitPlans[1].Selected = true;
JsonResult result = Json(lstBenefitPlans, JsonRequestBehavior.AllowGet);
return result;
}
&#13;
与剑道列表相关联的动作方法:
public ActionResult IndividualList(Int16 benefitPlanID, Int16 isPrimOrSecondary, [DataSourceRequest] DataSourceRequest request, bool Masked = false)
{
List<IndividualList> lIndList = new List<IndividualList>();
IndividualList ind = null;
decimal totalPercentage = 0;
DataSourceResult dataSourceResult = new DataSourceResult();
List<Entities.AssignedBeneficiariesByBeneficiary> l = null;
l = beneficiaryBL.GetAssignedBeneficiariesByBeneficiaryFormID(BeneficiaryFormID, benefitPlanID, isPrimOrSecondary);
if (l != null && l.Count > 0)
{
foreach (Entities.AssignedBeneficiariesByBeneficiary indv in l)
{
ind = new IndividualList();
ind.PlanLinkID = indv.PlanLinkID;
ind.IndividualID = indv.BeneficiaryID;
ind.FirstName = string.Concat(indv.FirstName, " ", indv.LastName);
ind.LastName = indv.LastName;
ind.Name = indv.FirstName + " " + indv.LastName;
lIndList.Add(ind);
}
}
dataSourceResult = lIndList.ToList().ToDataSourceResult(request);
JsonResult result = Json(dataSourceResult, JsonRequestBehavior.AllowGet);
return result;
}
&#13;