我在使用Bootstrap MVC表单时遇到了一些小问题。当我添加我的Razor代码时,form-group的边距似乎无法正常工作。希望能得到帮助。
这是未能正确应用样式的表单。
@using (Html.BeginForm("Contact", "Home"))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="formGroupInputLarge1" class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
@Html.TextBoxFor(m => m.Name, new { @class = "form-control", placeholder = "Fullname", tabindex = 1 })
@Html.ValidationMessageFor(m => m.Name)
</div>
</div>
<div class="form-group">
<label for="formGroupInputLarge2" class="col-sm-2 control-label">Email</label>
<div class="col-sm-10">
@Html.TextBoxFor(m => m.Email, new { @class = "form-control", placeholder = "Email Address", tabindex = 2 })
@Html.ValidationMessageFor(m => m.Email)
</div>
</div>
<div class="form-group">
<label for="formGroupInputLarge3" class="col-sm-2 control-label">Message</label>
<div class="col-sm-10">
@Html.TextAreaFor(m => m.Message, new { @class = "form-control", placeholder = "Message", tabindex = 3 })
@Html.ValidationMessageFor(m => m.Message)
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary btn-lg">Send Mail</button>
</div>
</div>
</form>
}
但是一旦我移除了Begin form标签,它就会采用正确的样式。
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="formGroupInputLarge1" class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
@Html.TextBoxFor(m => m.Name, new { @class = "form-control", placeholder = "Fullname", tabindex = 1 })
@Html.ValidationMessageFor(m => m.Name)
</div>
</div>
<div class="form-group">
<label for="formGroupInputLarge2" class="col-sm-2 control-label">Email</label>
<div class="col-sm-10">
@Html.TextBoxFor(m => m.Email, new { @class = "form-control", placeholder = "Email Address", tabindex = 2 })
@Html.ValidationMessageFor(m => m.Email)
</div>
</div>
<div class="form-group">
<label for="formGroupInputLarge3" class="col-sm-2 control-label">Message</label>
<div class="col-sm-10">
@Html.TextAreaFor(m => m.Message, new { @class = "form-control", placeholder = "Message", tabindex = 3 })
@Html.ValidationMessageFor(m => m.Message)
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary btn-lg">Send Mail</button>
</div>
</div>
</form>