【发布时间】:2019-10-10 22:54:25
【问题描述】:
当我尝试在第一个表单之后提交表单时,它只是调用该 post 方法,而不是用于提交按钮当前所在的表单的方法。我的印象是,无论您提交按钮的形式是什么,都会在页面上触发。
使用 ajax 辅助函数来解决它,但它并没有按照我想要的方式工作。
下面是部分代码here 是完整的。
Html.BeginForm("Create", "Comments", FormMethod.Post, new { @class = "form-control" });
{
@Html.AntiForgeryToken()
@Html.Hidden("BlogPostId", Model.Id);
<div class="row">
<div class="col-12">
@Html.Editor("Content", new { htmlAttributes = new { @id = "richTextEditor", @class = "form-control textarea", @placeholder = "Enter comment here.", @rows = 5, @cols = 10 } })
</div>
</div>
<div class="row" style="padding-top:2%">
<div class="col-2">
<button type="submit" class="btn btn-info waves-effect waves-light m-r-10">Submit</button>
</div>
</div>
}
@using (Html.BeginForm("Edit", "Comments", FormMethod.Post, new { @class = "form-control" }))
{
@Html.AntiForgeryToken()
@Html.Hidden("Id", comment.Id);
@Html.Hidden("BlogPostId", comment.BlogPostId);
@Html.Hidden("AuthorId", comment.AuthorId);
@Html.Hidden("CreateDate", comment.CreateDate);
@Html.Hidden("UpdateDate", comment.UpdateDate);
<div class="row">
<div class="col-12">
@Html.Editor("UpdateReason", new { htmlAttributes = new { @class = "form-control", @placeholder = "Enter comment here.", @rows = 5, @cols = 10 } })
</div>
</div>
<div class="row">
<div class="col-12">
@Html.Editor("Content", new { htmlAttributes = new { @id = "richTextCommentEditor", @class = "form-control textarea", @placeholder = "Enter comment here.", @rows = 5, @cols = 10 } })
</div>
</div>
<div class="row" style="padding-top:2%">
<div class="col-2">
<button type="submit" class="btn btn-info waves-effect waves-light m-r-10">Submit</button>
</div>
</div>
}
我没有收到任何错误,它只是导致调用创建评论的操作,而不是表单应该执行的操作。
【问题讨论】:
标签: c# model-view-controller asp.net-mvc-5