ASP.NET MVC异步提交表单
ASP.NET MVC异步提交表单
引用相关js文件
<script src="~/lib/jquery/dist/jquery.js"></script>
<script src="~/lib/jquery-ajax-unobtrusive/jquery.unobtrusive-ajax.min.js"></script>
通过Form元素添加属性
<form asp-controller="xxx" asp-action="xxx" data-ajax="true" data-ajax-method="post" data-ajax-begin="onBegin" data-ajax-complete="onComplete" data-ajax-failure="onFailed" data-ajax-success="onSuccess">
</form>
添加js异步回调
<script>
var onBegin = function () {
alert("asasas");
};
var onSuccess = function (result) {
alert(result);
};
</script>
@Ajax.Form helpers
AjaxOptions | HTML attribute |
---|---|
Confirm | data-ajax-confirm |
HttpMethod | data-ajax-method |
InsertionMode | data-ajax-mode |
LoadingElementDuration | data-ajax-loading-duration |
LoadingElementId | data-ajax-loading |
OnBegin | data-ajax-begin |
OnComplete | data-ajax-complete |
OnFailure | data-ajax-failure |
OnSuccess | data-ajax-success |
UpdateTargetId | data-ajax-update |
Url | data-ajax-url |
https://dotnetthoughts.net/jquery-unobtrusive-ajax-helpers-in-aspnet-core/
本文来自博客园,作者:weichangk,转载请注明原文链接:https://www.cnblogs.com/weichangk/p/15898619.html