@Html.BeginForm Displaying "System.Web.Mvc.Html.MvcForm" on Page

asp.net Mvc-3Razorhtml.beginform

asp.net Mvc-3 Problem Overview


I have a razor view that I added a delete button to inside of an 'if' statement and when the view is rendered in the browser it is displaying "System.Web.Mvc.Html.MvcForm" next to the delete button.

How do I get rid of it?

Here is the code:

<div id="deletestatusupdate">
    @if (update.User.UserName.Equals(User.Identity.Name, StringComparison.OrdinalIgnoreCase))
    {
        @Html.BeginForm("deleteupdate", "home")
        @Html.Hidden("returnUrl", Request.Url.ToString())
        <button name="id" value="@update.StatusUpdateId">Delete</button>
    }
</div>

Here is how it shows up in the rendered Razor View:

System.Web.Mvc.Html.MvcForm [Delete Button]

pretend that [delete button] is a an actual button, didn't feel like taking a screen shot.

Thank you for your help.

asp.net Mvc-3 Solutions


Solution 1 - asp.net Mvc-3

The recommended way to generate a form is the following:

<div id="deletestatusupdate">
    @if (update.User.UserName.Equals(User.Identity.Name, StringComparison.OrdinalIgnoreCase))
    {
        using(Html.BeginForm("deleteupdate", "home"))
        {
            @Html.Hidden("returnUrl", Request.Url.ToString())
            <button name="id" value="@update.StatusUpdateId">Delete</button>
        }
    }
</div>

Alternatively you could do this:

<div id="deletestatusupdate">
    @if (update.User.UserName.Equals(User.Identity.Name, StringComparison.OrdinalIgnoreCase))
    {
        Html.BeginForm("deleteupdate", "home");
        @Html.Hidden("returnUrl", Request.Url.ToString())
        <button name="id" value="@update.StatusUpdateId">Delete</button>
        Html.EndForm();
    }
</div>

The reason why your original approach did not work is because BeginForm() writes directly to the output.

Solution 2 - asp.net Mvc-3

Please use @using instead of using the issue will resolved I am using MVC 4

@using(Html.BeginForm("deleteupdate", "home"))
{
    @Html.Hidden("returnUrl", Request.Url.ToString())
    <button name="id" value="@update.StatusUpdateId">Delete</button>
}

Solution 3 - asp.net Mvc-3

enter image description here

Get right for this we can use them

Using(Html.Beginform("Delete", "Home", new { Id = item.id } )) { @* We right the code. *@ }

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTimothy GreenView Question on Stackoverflow
Solution 1 - asp.net Mvc-3marcindView Answer on Stackoverflow
Solution 2 - asp.net Mvc-3ANANTHView Answer on Stackoverflow
Solution 3 - asp.net Mvc-3Ashok Reddy MedikondaView Answer on Stackoverflow