我正在尝试在剃刀中创建一个水平形式,但我似乎无法应用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")' " />
}
这是它的样子:
答案 0 :(得分:1)
col-sm-3
col-sm-9
添加到包含输入的div form-group
div包装标签和包装输入的div。 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>