有没有办法让AjaxBeginForms忽略一些指定的按钮?
例如我的代码是:
@using (Ajax.BeginForm("CreatePost", "Accounts", new AjaxOptions
{
InsertionMode = InsertionMode.Replace,
HttpMethod = "POST",
LoadingElementId = "loading",
OnBegin = "TransferContentEditableToHiddenTextArea()",
OnSuccess = "$('#CreateMessage').css('display','block');",
UpdateTargetId = "CreateMessage"
}))
{
@Html.AntiForgeryToken()
@Html.Label("Post Title", new { @style = "padding-right:3px;" })
@Html.TextBoxFor(model => model.BlogTitle, new { @required = "require", @style = "width:100%;", @class = "form-control" })
@Html.Label("Post Blog", new { @style = "padding-right:3px;" })
<ul id="postModifierButtonsGroup">
<li><span class="btn btn-primary btn-xs" ><i class="fa fa-bold"></i></span></li>
<li><span class="btn btn-primary btn-xs" ><i class="fa fa-italic"></i></span></li>
<li><span class="btn btn-primary btn-xs" ><i class="fa fa-underline"></i></span></li>
</ul>
<p class="form-control" id="contentEditableTextBox" contenteditable="true"></p>
@Html.TextAreaFor(model => model.BlogPost, new { id = "hiddenTextbox", @required = "require", @style = "display:none;resize: none; width:100%; height: 130px; font: 16px tahoma;", @class = "form-control" })
<input type="submit" class="btn btn-success" value="Submit"/>
}
所以我有两个字段,一个帖子和一个标题,用c#后端进入ajax调用。问题是我只是添加了粗体,斜体和下划线按钮,它们与ajax表单相冲突。如果我想向我添加粗体文本表单已尝试提交。 有没有办法在按钮上指定它不是我的ajax调用的一部分?
答案 0 :(得分:3)
如果您不想要按钮提交表单,可以添加以下属性:
type="button"
如果任何按钮被标记为type =&#34;请提交&#34;在表单内部,它将提交该表单。