我有一个 DropDownlist 和 Webgrid。当我加载页面所有绑定的数据时,我需要根据 DropDownlist 的变化在 Webgrid 中绑定数据。我该怎么做。
我的代码是:
Script:
它将调用控制器函数
<script type="text/javascript">
$(document).ready(function () {
$("#Cust_Id").change(function () {
firstDDLValue = $("#Cust_Id").val();
$.post(
'@Url.Action("SelectCustomerByID", "Admin")',
{
secondValue: firstDDLValue
},
function (ReceiptList) {
});
});
});
</script>
Controller Code:
public ActionResult SelectCustomerByID(Receipt model,string secondValue)
{
int CustID = 0;
if (secondValue != "")
{
CustID = Convert.ToInt32(secondValue);
}
ObservableCollection<Receipt> ReceiptList = new ObservableCollection<Receipt>();
Receipt Receipt = new Models.Receipt();
model.ReceiptList = Receipt.GetReceiptListByCustID(CustID);
return View(model.ReceiptList);
}