我想在客户端通过 javascript 更改一些 MVC Ajax 表单参数,例如 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
生成 <form>
带有一系列 data-xxx
的标签基于 AjaxOptions
的属性, 例如
<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
关于javascript - 通过 JavaScript 更改 MVC Ajax 表单的插入模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26439305/