我想在网格顶部添加下拉列表。但它不能正常工作。我需要的是从下拉菜单中选择一个项目,并填充网格上所选项目的其余细节 但我得到了:
**The parameters dictionary contains a null entry for parameter 'itemIDFilter' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult _BinCard(Kendo.Mvc.UI.DataSourceRequest, Int32)' in X.Controllers.ItemsController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters**
控制器:
public ActionResult _ItemDropdown([DataSourceRequest] DataSourceRequest request)
{
//
var data = ReportEngineHelper.GetReportingEngine(Session).Generate<ItemDropDownQuery>().ToQueryModel<ItemDropDownModel>();
return Json(data.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}
public ActionResult _BinCard([DataSourceRequest] DataSourceRequest request, int itemIDFilter)
{
var data = ReportEngineHelper.GetReportingEngine(Session).Generate<BinCardQuery>(new Filter()
{
Item = new Item(){ItemID = itemIDFilter}
}).ToQueryModel<BinCard>();
return Json(data.ToDataSourceResult(request));
}
视图:
@using HCMIS.Dashboard.Core.Models.Items
@using Kendo.Mvc.UI
<table>
<tr>
<td> Item : </td>
<td>
@(
Html.Kendo().DropDownList()
.Name("Itemdropdownlist")
.DataTextField("FullItemName")
.DataValueField("ItemID")
.DataSource(source => source.Read(read => read.Action("_ItemDropdown", "Items")))
.OptionLabel("Select an Item") )
</td>
<td>
<img src="/Content/Images/go.png" valign="top" onclick="loadGrid('BinCardGrd', false)" alt="Go" title="Go" style="width:20px;height:18px;margin-top:2px" />
</td>
</tr>
</table>
@(
Html.Kendo().Grid<BinCard>()
.Name("BinCardGrd")
.AutoBind(false)
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("_BinCard", "Items").Data("readItemIdFilter")))
.Columns(columns =>
{
columns.Bound(c => c.Item).Width(550);
columns.Bound(c => c.Unit).Width(100);
columns.Bound(c => c.dateFormat).Title("Date").Width(200);
columns.Bound(c => c.InvoiceNo).Title("No.").Width(200);
columns.Bound(c => c.Received).Width(200);
columns.Bound(c => c.Issued).Width(200);
columns.Bound(c => c.SupplierTo).Title("Supplier/To").Width(200);
columns.Bound(c => c.Quantity).Title("Quantity").Width(200);
columns.Bound(c => c.Balance).Title("Balance").Width(200);
}
)
.Sortable()
)
<script>function readItemIdFilter() {
var IID = $("#Itemdropdownlist").data("kendoDropDownList");
return {
itemIDFilter: (IID.dataValueField)
};
} </script>
模型:
public class ItemDropDownModel
{
public int ItemID{ get; set; }
public string FullItemName { get; set; }
public string ItemWithCommodityType { get; set; }
}
BinCardQuery:
public override string Generate()
{
QueryString = string.Format(@"`
Select FullItemName Item,`
Unit, GRNFDate [Date], Supplier, Null InvoiceNo, Received, Issued,
SUM(IsNull(Received,0) - IsNull(Issued, 0))
OVER (ORDER BY RowNumber asc) As Balance
From Transactions.StockOnHandBase
where EnvironmentID = {0} and itemid = {1}
", EnvironmentID, Item.ItemID);
return QueryString;
}
public Item Item { get; set; }
答案 0 :(得分:0)
请尝试使用以下代码段。
查看强>
@(
Html.Kendo().DropDownList()
.Name("Itemdropdownlist")
.DataTextField("FullItemName")
.DataValueField("ItemID")
.DataSource(source => source.Read(read => read.Action("_ItemDropdown", "Home")))
.OptionLabel("Select an Item"))
<强> CONTROLLER 强>
public JsonResult _ItemDropdown()
{
List<ItemDropDownModel> lst = new List<ItemDropDownModel>();
lst.Add(new ItemDropDownModel() { ItemID = 1, FullItemName = "1", ItemWithCommodityType = "1" });
lst.Add(new ItemDropDownModel() { ItemID = 11, FullItemName = "11", ItemWithCommodityType = "11" });
lst.Add(new ItemDropDownModel() { ItemID = 111, FullItemName = "111", ItemWithCommodityType = "111" });
return Json(lst, JsonRequestBehavior.AllowGet);
}
此外,我还更新了您的控制器代码。
public JsonResult _ItemDropdown()
{
var data = ReportEngineHelper.GetReportingEngine(Session).Generate<ItemDropDownQuery>().ToQueryModel<ItemDropDownModel>();
return Json(data, JsonRequestBehavior.AllowGet);
}
如果有任何疑虑,请告诉我。
更新1:
查看强>
@(
Html.Kendo().DropDownList()
.Name("Itemdropdownlist")
.DataTextField("FullItemName")
.DataValueField("ItemID")
.DataSource(source => source.Read(read => read.Action("_ItemDropdown", "Home")))
.OptionLabel("Select an Item")
.Events(e =>
{
e.Change("onChanges");
})
)
<br />
@(
Html.Kendo().Grid<MvcApplication1.Models.BinCard>()
.Name("BinCardGrd")
.AutoBind(false)
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("_BinCard", "Home").Data("readItemIdFilter")))
.Columns(columns =>
{
columns.Bound(c => c.Item).Width(550);
columns.Bound(c => c.Unit).Width(100);
}
)
.Sortable()
)
<script>
function readItemIdFilter() {
var IID = $("#Itemdropdownlist").data("kendoDropDownList");
var ddvalue = 0;
debugger;
if (IID.dataItem() && IID.dataItem().ItemID) {
ddvalue = IID.dataItem().ItemID;
}
return {
itemIDFilter: ddvalue
};
}
function onChanges(e) {
$('#BinCardGrd').data('kendoGrid').dataSource.read();
$('#BinCardGrd').data('kendoGrid').refresh();
}
</script>
<强> CONTROLLER 强>
public JsonResult _ItemDropdown()
{
List<ItemDropDownModel> lst = new List<ItemDropDownModel>();
lst.Add(new ItemDropDownModel() { ItemID = 1, FullItemName = "1", ItemWithCommodityType = "1" });
lst.Add(new ItemDropDownModel() { ItemID = 11, FullItemName = "11", ItemWithCommodityType = "11" });
lst.Add(new ItemDropDownModel() { ItemID = 111, FullItemName = "111", ItemWithCommodityType = "111" });
return Json(lst, JsonRequestBehavior.AllowGet);
}
public ActionResult _BinCard([DataSourceRequest] DataSourceRequest request, int itemIDFilter)
{
List<BinCard> lst = new List<BinCard>();
lst.Add(new BinCard() { Item = "2", Unit = itemIDFilter.ToString() });
lst.Add(new BinCard() { Item = "22", Unit = itemIDFilter.ToString() });
lst.Add(new BinCard() { Item = "222", Unit = itemIDFilter.ToString() });
return Json(lst.ToDataSourceResult(request));
}