本文介绍了@ Html.BeginForm显示" System.Web.Mvc.Html.MvcForm"上页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我添加了一个删除按钮到一个'如果'的语句,当鉴于在浏览器中呈现它显示的System.Web.Mvc.Html.MvcForm里面的剃刀视图旁边的删除按钮。

I have a razor view that I added a delete button to inside of a 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.

我该如何摆脱它?

下面是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>

这里是如何在渲染的Razor视图显示出来:

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

pretend的[删除键]是一个实际的按钮,不喜欢采取的屏幕截图。

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

感谢您的帮助。

推荐答案

要生成表单的建议方法如下:

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>

为什么你原来的做法不工作的原因是因为 BeginForm()直接写入到输出。

这篇关于@ Html.BeginForm显示&QUOT; System.Web.Mvc.Html.MvcForm&QUOT;上页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 02:44