如何在 MVC 视图的同一行中显示 @Html htmlhelper 和 @using?

How to display @Html htmlhelper and @using in same line in MVC views?

  1. 我试图在同一行显示所有这三个助手。

  2. 弹出窗口也未显示,要求在单击按钮时确认。

但是按钮显示在我使用@using 创建的下一行:

<td>
    @Html.ActionLink("Edit", "Edit", new { id = item.EmployeeId }) |
    @Html.ActionLink("Details", "Details", new { id = item.EmployeeId }) |
    @using (Html.BeginForm("Delete", "BusinessLayer", new { id = item.EmployeeId }))
    {
         <input type="submit" value="Delete" onclick="return conform('Are you sure you want to delete record with EmployeeId = @item.EmployeeId')" />
    }
</td>

有什么方法可以在同一行显示吗

正确地指出这个问题与 CSS.Since 有关,整个 CSS 不可用我在这里使用内联样式。

<td style="width:100%;">
    @Html.ActionLink("Edit", "Edit", new { id = item.EmployeeId,@style="width:33.33%" }) 
    @Html.ActionLink("Details", "Details", new { id = item.EmployeeId,@style="width:33.33%"})
    @using (Html.BeginForm("Delete", "BusinessLayer", new { id = item.EmployeeId,@style="width:33.33%"}))
    {
         <input type="submit" value="Delete" onclick="return conform('Are you sure you want to delete record with EmployeeId = @item.EmployeeId')" />
    }
</td>

但我强烈建议使用 CSS 而不是内联样式。

按钮显示在下一行,因为 @using (Html.BeginForm) 环绕着它。由于 <form> 是一个块元素,该元素将在 'new line'.

上呈现

将表单环绕所有控件,或将表单显示更改为内联(或内联块)元素。