我有三个HTML下拉列表(由于性能而没有使用kendo下拉列表),在选择之后转到我的控制器操作并回发以更新网格。问题出在我进行第一次选择之后,之后的每个选择都将其设置回第一个选定值,因此新参数永远不会传递给我的控制器。
这是我的观点
<link href="~/Content/kendo/2014.1.318/kendo.default.min.css" rel=" stylesheet" />
<link href="~/Content/kendo/2014.1.318/kendo.common.min.css" rel="stylesheet" />
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/Kendo")
@Html.Label("AB_ID: ")
@Html.DropDownList("AB_ID", null, "--SELECT--", htmlAttributes: new { @class = "btn btn-success dropdown-toggle" })
@Html.Label("AB_TYPE: ")
@Html.DropDownList("AB_TYPE", null, "--SELECT--", htmlAttributes: new { @class = "btn btn-success dropdown-toggle" })
@Html.Label("A_DD_ID: ")
@Html.DropDownList("A_DD_ID", null, "--SELECT--", htmlAttributes: new { @class = "btn btn-success dropdown-toggle" })
@(Html.Kendo().Grid(Model)
.Name("Grid")
.DataSource(data => data
.Server()
.Read(read => read.Action("Grid_Read", "ASSETs"))
.PageSize(10))
.Pageable()
.Sortable()
)
<script>
function passData() {
var param = {};
param.ab_id = $("#AB_ID").val();
param.ab_type = $("#AB_TYPE").val();
param.a_dd_id = $("#A_DD_ID").val();
return param;
}
$(".dropdown-toggle").on("change", function () {
var data = passData();
var grid = $("#Grid").data("kendoGrid");
grid.dataSource.read(data);
});
这是我的控制器
public ActionResult Grid_Read([DataSourceRequest] DataSourceRequest request, string ab_id, string ab_type,
string a_dd_id)
{
IQueryable<ASSET> assets = null;
if (!string.IsNullOrEmpty(ab_id) || !string.IsNullOrEmpty(ab_type) || !string.IsNullOrEmpty(a_dd_id))
{
if (!string.IsNullOrEmpty(ab_id)
&& !string.IsNullOrEmpty(ab_type)
&& !string.IsNullOrEmpty(a_dd_id)
)
{
assets = db.ASSETs.Join(db.ASSET_BASE,
c => c.A_AB_NO,
cm => cm.AB_NO, (c, cm) => new { A = c, AB = cm })
.Where(c => c.AB.AB_ID == ab_id && c.AB.AB_TYPE == ab_type && c.A.A_DD_ID == a_dd_id)
.Select(x => x.A);
}
else if (!string.IsNullOrEmpty(ab_id) && !string.IsNullOrEmpty(ab_type) )
{
assets = db.ASSETs.Join(db.ASSET_BASE,
c => c.A_AB_NO,
cm => cm.AB_NO, (c, cm) => new { A = c, AB = cm })
.Where(c => c.AB.AB_ID == ab_id && c.AB.AB_TYPE == ab_type)
.Select(x => x.A);
}
else if (!string.IsNullOrEmpty(ab_id) )
{
assets = db.ASSETs.Join(db.ASSET_BASE,
c => c.A_AB_NO,
cm => cm.AB_NO, (c, cm) => new { A = c, AB = cm })
.Where(c => c.AB.AB_ID == ab_id)
.Select(x => x.A);
}
else if (!string.IsNullOrEmpty(ab_type) && !string.IsNullOrEmpty(a_dd_id) )
{
assets = db.ASSETs.Join(db.ASSET_BASE,
c => c.A_AB_NO,
cm => cm.AB_NO, (c, cm) => new { A = c, AB = cm })
.Where(c => c.AB.AB_TYPE == ab_type && c.A.A_DD_ID == a_dd_id)
.Select(x => x.A);
}
else if (!string.IsNullOrEmpty(ab_id) && !string.IsNullOrEmpty(a_dd_id) )
{
assets = db.ASSETs.Join(db.ASSET_BASE,
c => c.A_AB_NO,
cm => cm.AB_NO, (c, cm) => new { A = c, AB = cm })
.Where(c => c.AB.AB_ID == ab_id && c.A.A_DD_ID == a_dd_id)
.Select(x => x.A);
}
else if (!string.IsNullOrEmpty(ab_type) )
{
assets = db.ASSETs.Join(db.ASSET_BASE,
c => c.A_AB_NO,
cm => cm.AB_NO, (c, cm) => new { A = c, AB = cm })
.Where(c => c.AB.AB_TYPE == ab_type)
.Select(x => x.A);
}
else if (!string.IsNullOrEmpty(a_dd_id))
{
assets = db.ASSETs.Join(db.ASSET_BASE,
c => c.A_AB_NO,
cm => cm.AB_NO, (c, cm) => new {A = c, AB = cm})
.Where(c => c.A.A_DD_ID == a_dd_id)
.Select(x => x.A);
}
}
if (assets == null)
assets = db.ASSETs;
ViewBag.AB_ID = new SelectList(db.ASSET_BASE.Select(x => x.AB_ID).Distinct().OrderBy(x => x));
ViewBag.AB_TYPE = new SelectList(db.ASSET_BASE.Select(x => x.AB_TYPE).Distinct().OrderBy(x => x));
ViewBag.A_DD_ID = new SelectList(db.DICTIONARies.Select(x => x.DD_ID).Distinct().OrderBy(x => x));
return View("Index", assets);
}
我尝试使用以下内容更改数据源,但似乎仍然没有使用我的新参数更新数据源。我也尝试将网格从服务器端网格更改为客户端网格,结果相同。
var dataSource = new kendo.data.DataSource({
data: [
passData()
]
});
grid.setDataSource(dataSource);