我想通过Ajax调用控制器,但我怎么能使用JQUERY-UNOBTRUSIVE不使用表单标签



我们可以通过使用像

这样的表单标签轻松地调用控制器
<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-ajaxdata-ajax-modedata-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

最新更新