水平表格类没有应用bootstrap Razor

时间:2014-08-22 20:21:52

标签: html css asp.net-mvc twitter-bootstrap razor

我正在尝试在剃刀中创建一个水平形式,但我似乎无法应用CSS。其他所有东西都有正确的CSS,但是当我尝试将类添加到BeginForm或甚至正常时它都不起作用。

以下是我的观点:

@using (Html.BeginForm(Html.BeginForm("Default", "Employee", null, FormMethod.Post, new { @class = "form-horizontal" })))
{
        <h2>Employee Search</h2>
            <fieldset>
                <div class="form-group">
                    @Html.Label("Company: ", new { @class = "control-label" })
                </div>
                <div>
                    @Html.DropDownList("cono", (List<SelectListItem>)ViewBag.CompanyList, new { @class = "form-control" })
                </div>
                <div class="form-group">
                    @Html.Label("First Name: ", new { @class = "control-label" })
                </div>
                <div>
                    @Html.TextBox("firstName", Session["firstname"], new { @class = "form-control" })
                </div>
                <div class="form-group">
                    @Html.Label("Last Name: ", new { @class = "control-label" })
                </div>
                <div>
                    @Html.TextBox("lastName", Session["lastname"], new { @class = "form-control" })
                </div>
                <div class="form-group">
                    @Html.Label("Branch: ", new { @class = "control-label" })
                </div>
                <div>
                    @Html.DropDownList("branch", (List<SelectListItem>)ViewBag.BranchList, new { @class = "form-control" })
                </div>
                <div class="form-group">
                    @Html.Label("Sales Rep: ", new { @class = "control-label" })
                    @Html.TextBox("salesRep", Session["salesrep"], new { @class = "form-control" })
                </div>
                <div class="form-group">
                    @Html.Label("Status Type: ", new { @class = "control-label" })
                    @Html.DropDownList("statusType", (List<SelectListItem>)ViewBag.StatusTypeList, new { @class = "form-control" })
                </div>

            </fieldset>
            <input type="submit" class="btn btn-default" name="DefaultPost" value="Search" />
            <input type="button" value="Clear" class="btn btn-default" onclick="location.href='@Url.Action("Default", "Employee")' " />
}

这是它的样子:

enter image description here

1 个答案:

答案 0 :(得分:1)

  1. 删除包裹标签的div
  2. 为标签添加列类col-sm-3
  3. 将列类col-sm-9添加到包含输入的div
  4. 确保form-group div包装标签和包装输入的div。
  5. Razor语法

    <div class="form-group">
        @Html.Label("Company: ", new { @class = "col-sm-3 control-label" })
        <div class="col-sm-9">
            @Html.DropDownList("cono", (List<SelectListItem>)ViewBag.CompanyList, new { @class = "form-control" })
       </div>
    </div>
    

    纯HTML格式......

      <div class="form-group">
        <label for="inputEmail3" class="col-sm-2 control-label">Email</label>
        <div class="col-sm-10">
          <input type="email" class="form-control" id="inputEmail3" placeholder="Email">
        </div>
      </div>