我想在客户端通过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>
}
答案 0 :(得分:2)
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