我们可以通过使用像
这样的表单标签轻松地调用控制器<form asp-action="PartialAction" data-ajax="true" data-ajax-mode="replace" data-ajax-
update="#ProductList">
<input type="text" name="name" /><input type="submit" />
</form>
现在我想用ajax调用action。如何在ajax调用中使用data-ajax, data-ajax-mode和data-ajax-updata属性
var Categories = function (Key,Length) {
$.ajax(
{
type: "POST",
url: "/ShopGrid/PartialAction",
data: { GrpKey: array },
success: function (response) {
}
})
}
data-ajax
、data-ajax-mode
和data-ajax-update
的效果等于在ajax成功函数中使用.html()
方法:
success: function (response) {
$("#ProductList").html(response);
}
您可以在这里查看jquery-unobtrusive-ajax.js
源代码:
https://github.com/aspnet/jquery-ajax-unobtrusive/blob/main/src/jquery.unobtrusive-ajax.js L55