gpt4 book ai didi

c# - 如何使用 jquery 在不刷新页面的情况下刷新 View 组件

转载 作者:行者123 更新时间:2023-12-05 02:38:24 25 4
gpt4 key购买 nike

我的 View 中有一个 View 组件

 @await Component.InvokeAsync("UserProfileCard")

我想当我点击一个按钮时只有这个组件会被刷新而不用使用 jquery ajax 或 jquery Unobtrusive 刷新页面

最佳答案

围绕组件创建div

<div id="userProfileCard">
@await Component.InvokeAsync("UserProfileCard")
</div>

创建 Action

public class MyController : Controller {
public IActionResult GetUserProfileCardComponent() {
return ViewComponent("UserProfileCard", <arguments...>);
}
}

Ajax

<script>
$.get("/MyController/GetUserProfileCardComponent", function(data) {
$("#userProfileCard").html(data);
});
</script>

关于c# - 如何使用 jquery 在不刷新页面的情况下刷新 View 组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69604048/

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