@ Html. BeginForm 在页面上显示“ System.Web.Mvc.Html. MvcForm”

我有一个剃须刀视图,我添加了一个删除按钮的内部’如果’语句,当视图呈现在浏览器中,它是显示 “ System.Web.Mvc.Html.MvcForm”旁边的删除按钮。

我怎么才能摆脱它?

密码如下:

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

下面是它在渲染的 Razor 视图中的显示方式:

System.Web.Mvc.Html.MvcForm < strong > [删除按钮]

假装[删除按钮]是一个实际的按钮,不想采取屏幕截图。

谢谢你的帮助。

43042 次浏览

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.

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

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