我看到一张表格。

@if (Request.IsAuthenticated) {
     @(Html.BeginForm("LeaveComment", "Publication")){
          <input type="text" name="pub" style="display: none" [email protected]>
          <input type="text" name="mail"  style="display: none" [email protected]>
          <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)

我该怎么解决?
编辑
如果我使用@使用这个很好,但这个崩溃另一个形式。下一个是另一个表单的代码:
@if(请求。已验证)
{
            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的问题,并删除了此文章的字段FormMethod.Post。

最佳答案

您需要使用using (Html.BeginForm(...)),因为MvcForm.Dispose()将打印实际的结束表单标记。
您的代码@(Html.BeginForm)将调用MvcForm.ToString(),这将只打印类型名。

10-04 18:36