我想在我的网格顶部添加下拉列表。但它不能正常工作。我需要的是从下拉菜单中选择一个项目并填充网格上所选项目的其余详细信息,但我得到:
**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; }
}
BinCard查询:
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; }