gpt4 book ai didi

c# - 如何使用 PartialView 在 ASP.Net MVC 的 webgrid 中绑定(bind)数据

转载 作者:行者123 更新时间:2023-11-30 17:50:09 25 4
gpt4 key购买 nike

我有一个 DropDownlist 和 Webgrid。当我在 Bind 中加载页面所有数据时,我需要根据 DropDownlist 的变化在 Webgrid 中绑定(bind)数据。我该怎么做。

我的代码是:

脚本:

它将调用 Controller 函数

<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 代码:

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);
}

最佳答案

您应该在操作中返回一个 PartialView:

return PartialView(model.ReceiptList);

这仅在您有名为 SelectCustomerByID 的 View 时有效。如果您有一个具有其他名称的 View ,您可以在重载中指定它:

return PartialView("_NameOfPartialView", model.ReceiptList);

然后在 $.post()success 函数中:

function (ReceiptList) {
// ReceiptList will contain the html of the grid.
$('#id-of-datagrid').html(ReceiptList);
}

注意:我认为您必须从 SelectCustomerByID 中删除 Receipt model 参数。

关于c# - 如何使用 PartialView 在 ASP.Net MVC 的 webgrid 中绑定(bind)数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19197476/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com