gpt4 book ai didi

c# - ajax beginForm 忽略指定按钮

转载 作者:行者123 更新时间:2023-12-01 07:53:55 25 4
gpt4 key购买 nike

有没有办法让 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"/>
}

所以我有 2 个字段,一个帖子和一个标题,它们将进入 C# 后端的 ajax 调用。问题是我刚刚添加了粗体、斜体和下划线按钮,它们与ajax表单冲突。如果我想在文本中添加粗体,则该表单已尝试提交。有没有办法在按钮上指定它不属于我的 ajax 调用的一部分?

最佳答案

如果您不希望使用按钮来提交表单,您可以添加此属性:

type="button"

如果表单内的任何按钮被标记为 type="submit",它将提交该表单。

关于c# - ajax beginForm 忽略指定按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26307238/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com