将Ajax.BeginForm("Index", new AjaxOptions(...))
与提交按钮一起使用时。它调用动作方法两次。可能是什么原因?当我用Ajax.BeginForm
替换Html.BeginForm
时,它可以正常工作。
@using (Ajax.BeginForm(new AjaxOptions { OnSuccess = "onTemplateSaveSuccess(data);", OnComplete = "hideProgress();" }))
{
@Html.AntiForgeryToken()
<input type="hidden" name="templatePageNumber" id="templatePageNumber" />
<input type="hidden" name="templatePageSize" id="templatePageSize" />
@Html.HiddenFor(model => model.TemplateCode)
<div class="event-subheading">Templates </div>
<div id="TemplateInputDiv">
<fieldset>
<ul>
<li>
<label>Template Name </label>
@Html.TextBoxFor(model => model.TemplateName)
@Html.ValidationMessageFor(model => model.TemplateName)
</li>
<li>
<label>Type</label>
<input type="radio" name="TemplateType" class="radio-cover" value="1" checked="checked" /><span class="radio-txt">Email </span> <input type="radio" name="TemplateType" class="radio-cover" value="2" /> <span class="radio-txt">SMS </span> <input type="radio" name="TemplateType" class="radio-cover" value="3" /><span class="radio-txt">Badge</span>
<div class="clearfix"></div>
</li>
<li>
<label>Content </label>
@Html.TextAreaFor(model => model.TemplateContent, 10, 40, null)
@Html.ValidationMessageFor(model => model.TemplateContent)
</li>
<li>
<label></label><a href="myModal" data-toggle="modal" data-target="#myModal"><label class="hint--success" style="color:#23527c;font-weight:bold;" data-hint="Use hand button in the Dynamic Data window to insert the dynamic data tag to the current position of the editor."><b>Dynamic Data</b></label></a>
<span></span>
</li>
<li>
<label></label>
<input type="submit" value="Save" id="submitTemplate" name="submitTemplate" class="sub_mit" />
<input type="reset" value="Cancel" class="sub_mit" id="cancel" />
</li>
</ul>
</fieldset>
<div class="clearfix"></div>
</div>
}
答案 0 :(得分:0)
检查 onTemplateSaveSuccess(data); 方法,也许它会再次触发ajax reuqest。
答案 1 :(得分:0)
请分享onTemplateSaveSuccess方法的代码。尝试从此方法返回false并在此方法的末尾设置e.preventDefault()。如果这不起作用,那么尝试写e.stopPropagation()