ビューにフォームがあります。
@if (Request.IsAuthenticated) {
@(Html.BeginForm("LeaveComment", "Publication")){
<input type="text" name="pub" style="display: none" value=@publication.PublicationID>
<input type="text" name="mail" style="display: none" value=@Context.User.Identity.Name>
<textarea id="comment" name="comment"></textarea>
<button type="submit">Submit</button>
}
}
ビューには「System.Web.Mvc.Html.MvcForm」が表示されます。
コントローラーのメソッドは次のとおりです。
public ActionResult LeaveComment(int pub, string mail, string comment)
どうすれば解決できますか?
編集 @using を使用すると、これはうまく機能しますが、別のフォームがクラッシュします。他のフォームのコードは次のとおりです。
@if (Request.IsAuthenticated) {
using(Html.BeginForm("LeaveComment", "Publication", FormMethod.Post,
new { publicationID = publication.PublicationID, mail = Context.User.Identity.Name }))
{
<textarea id="comment" name="comment" style="width: 828px; margin-left: 18px;"></textarea>
<button type="submit" name="action:LeaveComment" value="LeaveComment" class="btn btn-default pull-right">
<strong>Submit</strong>
</button>
}
}
else
{
<form action="#">
<textarea id="comment" name="" style="width: 828px; margin-left: 18px;"></textarea>
<button type="button" href="#login" data-toggle="modal" data-target="#login-modal" class="btn btn-default pull-right" style="margin-right: 15px;">
Submit
</button>
</form>
}
更新 この問題を解決するには、コメントを残して使用し、この投稿の FormMethod.Post フィールドを削除しました。