【问题标题】:Bootstrap display of Form表单的引导显示
【发布时间】:2018-05-13 16:03:30
【问题描述】:

这对我来说没有意义。我正在尝试在我的 MVC5 项目中显示一个带有 4 个输入字段的表单。当我不使用 @using (HTML.BeginForm(...){..}

@using (Html.BeginForm("Create", "HR", FormMethod.Post)) {

我的显示器看起来很完美

但是一旦我输入@using (HTML.BeginForm(..) 语句,那么显示如下所示:

我的 html 助手哪里出错了?

这是我正在使用的一些示例 html 辅助方法..

<div class="panel-group">
<div class="panel panel-primary">
    <div class="panel-heading"><h4>Create New Employee</h4></div>
    <div class="panel-body"> 
        <form class="form-horizontal">
     <div class="form-group">
                    <label class="control-label col-sm-2">First Name</label>
                    <div class="col-sm-10"> 
                        @Html.TextBoxFor(m => m.FirstName, new { @class = "form-control", placeholder = "Enter First Name" })
                    </div>
             </div>
     <div class="form-group">
                    <label class="control-label col-sm-2" for="pwd">Middle Name</label>
                    <div class="col-sm-10"> 
                        @Html.TextBoxFor(m => m.MiddleName, new { @class = "form-control", placeholder = "Enter Middle Name" })
                    </div>
             </div>
     </form> 
  </div>
   </div> 

【问题讨论】:

  • 您是指Html.BeginForm()&lt;form class="form-horizontal"&gt;(无效的html)还是&lt;form class="form-horizontal"&gt;
  • 是的,如果我删除了
    ,并且只有 Html.BeginForm(),则显示与图像 2 相同

标签: css asp.net-mvc-5 bootstrap-4


【解决方案1】:

看起来您在使用@Html.BeginForm 时丢失了类属性。像这样添加回来:

<div class="panel-group">
<div class="panel panel-primary">
    <div class="panel-heading"><h4>Create New Employee</h4></div>
    <div class="panel-body"> 
    @using (Html.BeginForm("ActionName", "ControllerName", FormMethod.Post, new { @class="form-horizontal" }))
    {
     <div class="form-group">
                    <label class="control-label col-sm-2">First Name</label>
                    <div class="col-sm-10"> 
                        @Html.TextBoxFor(m => m.FirstName, new { @class = "form-control", placeholder = "Enter First Name" })
                    </div>
             </div>
     <div class="form-group">
                    <label class="control-label col-sm-2" for="pwd">Middle Name</label>
                    <div class="col-sm-10"> 
                        @Html.TextBoxFor(m => m.MiddleName, new { @class = "form-control", placeholder = "Enter Middle Name" })
                    </div>
             </div>
     }
  </div>
</div> 

【讨论】:

  • 感谢您的及时回复,只要我在“@using”语句中添加了属性,它就会立即生效。我快疯了。再次感谢。
猜你喜欢
  • 1970-01-01
  • 2017-11-20
  • 1970-01-01
  • 2017-04-22
  • 2021-03-15
  • 2019-02-03
  • 2014-05-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多