2

ビューにフォームがあります。

@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 フィールドを削除しました。

4

1 に答える 1

3

実際の end form タグを出力するのでusing (Html.BeginForm(...))、を使用する必要があります。MvcForm.Dispose()

コード@(Html.BeginForm)は を呼び出しMvcForm.ToString()、型名を出力するだけです。

于 2015-05-27T20:38:53.350 に答える