【发布时间】:2014-06-02 03:32:44
【问题描述】:
将 Bootstrap 3 用作 C# ASP.NET MVC5 项目的一部分。
我在尝试使用 input-group-addon 向表单字段添加“GB”后缀时遇到了一个非常奇怪的问题。
这是 C#:
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<hr />
@Html.ValidationSummary(true)
<div class="form-group">
@Html.LabelFor(model => model.capacity, new { @class = "control-label col-md-2" })
<div class="col-md-10">
<div class="input-group">
@Html.TextBoxFor(model => model.capacity, new { @class = "form-control" })
<span class="input-group-addon">GB</span>
</div>
@Html.ValidationMessageFor(model => model.capacity)
</div>
</div>
</div>
}
相当于:
<form action="/NewSpaceRequest/Create" method="post"><input name="__RequestVerificationToken" type="hidden" value="tP5XKKhflSS8K1e7q1I_ZSuR8Ty7X88FfuOMG5JhmF-KXtUOcn4SQdNGTMZZVC2pdBMjb7RgNrIB90Y9I5C_FgX9xmMLrwrbiFZde7PRZ13gCqjBDAVglM38T7j09-C-uNkRSCZbFqDgiU_XcH9D-w2" />
<div class="form-horizontal">
<hr />
<div class="form-group">
<label class="control-label col-md-2" for="capacity">Capacity</label>
<div class="col-md-10">
<div class="input-group">
<input class="form-control" data-val="true" data-val-number="The field Capacity must be a number." data-val-range="The field Capacity must be between 1 and 2147483647." data-val-range-max="2147483647" data-val-range-min="1" data-val-required="The Capacity field is required." id="capacity" name="capacity" type="text" value="" />
<span class="input-group-addon">GB</span>
</div>
<span class="field-validation-valid" data-valmsg-for="capacity" data-valmsg-replace="true"></span>
</div>
</div>
</div>
</form>
注意后缀如何没有被“拉到左边”到表单域?
不知道为什么。
【问题讨论】:
-
我已经在this plunker 中测试了您的 html,工作正常。您能否在浏览器中检查该元素应用了哪些其他样式?可能是这种情况,您为输入设置了固定宽度
-
你完全正确。我什至没有意识到,但 MVC5 在引导程序之上有自己的样式,每个样式都将输入的最大宽度设置为 280px。谢谢。
-
太好了,很高兴有帮助
标签: c# css twitter-bootstrap