Ignacio Chiazzo Ignacio Chiazzo - 5 months ago 12x
HTML Question

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

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?

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">
<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;">

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


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.