gpt4 book ai didi

asp.net-mvc - 您可以只更新部分 View 而不是整页帖子吗?

转载 作者:行者123 更新时间:2023-12-03 21:29:41 25 4
gpt4 key购买 nike

有没有办法在asp.net mvc中提交部分 View 表单而不重新加载父页面,而是仅将部分 View 重新加载到其新状态?类似于 knockout.js 使用数据绑定(bind)更新的方式。

我的数据表使用可变数量的列/名称进行渲染,因此我认为 Knockout.js 不适合此选项,因此我尝试使用部分 View 。

最佳答案

没有 jQuery 就不行。

你需要做的就是把你的 Partial 放在一个 div 中,比如:

<div id="partial">
@Html.Partial("YourPartial")
</div>

然后,要更新(例如单击 id button 的按钮),您可以执行以下操作:

$("#button").click(function () {
$.ajax({
url: "YourController/GetData",
type: "get",
data: $("form").serialize(), //if you need to post Model data, use this
success: function (result) {
$("#partial").html(result);
}
});
})

那么你的操作将类似于:

public ActionResult GetData(YourModel model) //that's if you need the model
{
//do whatever

return View(model);
}

关于asp.net-mvc - 您可以只更新部分 View 而不是整页帖子吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15146212/

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