2

I have a form in a View.

@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>
     }
}

The view show me "System.Web.Mvc.Html.MvcForm":

The method of controller is :

 public ActionResult LeaveComment(int pub, string mail, string comment)

How can I solve it?

EDIT If I use @using this work well but this crash another Form. The code of the other Form is the next :

@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>
        }

UPDATE I resolve this problem adding using in the leave comment and I deleted the field FormMethod.Post of this post.

4

1 回答 1

3

You need to use using (Html.BeginForm(...)), as MvcForm.Dispose() will print the actual end form tag.

Your code @(Html.BeginForm) will call MvcForm.ToString(), which will just print the type name.

于 2015-05-27T20:38:53.350 回答