System.Web.Mvc.Html.MvcForm 剃刀给我看 HTML

System.Web.Mvc.Html.MvcForm Razor show me a HTML

我在视图中有一个表单。

@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 这个效果很好,但是这会导致另一个 Form 崩溃。另一个Form的代码是下一个:

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

更新 我解决了这个问题,在评论中添加了 using 并删除了这个 post.

的字段 FormMethod.Post

您需要使用 using (Html.BeginForm(...)),因为 MvcForm.Dispose() 将打印实际的结束表单标记。

您的代码 @(Html.BeginForm) 将调用 MvcForm.ToString(),它只会打印类型名称。