通过JavaScript更改MVC Ajax表单的InsertionMode
本文关键字:表单 InsertionMode Ajax MVC JavaScript 更改 通过 | 更新日期: 2023-09-27 18:26:55
我想在客户端通过javascript更改一些MVC Ajax Form参数,如InsertionMode
或LoadingElementId
我该怎么做?
MVC ajax表单示例:
@using (Ajax.BeginRouteForm("DevicesByObjectName", new AjaxOptions
{
InsertionMode = InsertionMode.InsertBefore,
UpdateTargetId = "Devices",
LoadingElementId = "LoaderContents",
OnSuccess = "MoreDevicesOnSuccess",
OnFailure = "MoreDevicesOnFailure",
OnBegin = "MoreDevicesOnBegin",
OnComplete = "MoreDevicesOnComplete",
}))
{
<div>
@Html.AntiForgeryToken()
<input type="hidden" value="@Model.Object.Id" id="ObjectId" name="ObjectId" />
<input type="hidden" value="2" id="PageNumber" name="PageNumber" />
<input type="hidden" value="" id="Filtering" name="Filtering" />
<div class="center-block" style="max-width: 360px;">
<input type="submit" value=" more" class="btn btn-primary btn-lg btn-block center-block" />
</div>
<div id="LoaderContents" class="ajax-loader center-block hidden"></div>
</div>
}
BeginRouteForm
基于AjaxOptions
生成具有一系列data-xxx
属性的<form>
标签,例如
<form ... data-ajax-loading="#LoaderContents" data-ajax-mode="before" ...>
您可以使用jquery的.data()
或.attr()
方法来获取和设置这些。因此,对于您的助手生成的表单
console.log($('form').data('ajax-mode')); // returns before
$('form').data('ajax-mode', 'after'); // change the insertion mode
console.log($('form').data('ajax-mode')); // returns after