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>
}
}
public ActionResult LeaveComment(int pub, string mail, string comment)
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>
}
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.