Twitterbootstrap input-groups with Razor syntax

2019-08-09 19:58发布

I'm trying to convert this html:

<div class="col-lg-6">
    <div class="input-group">
      <span class="input-group-addon">
        <input type="checkbox">
      </span>
      <input type="text" class="form-control">
    </div><!-- /input-group -->
</div><!-- /.col-lg-6 -->

Into Razor syntax like this:

<div class="col-lg-6">
    <div class="input-group">
        <span class="input-group-addon">
            @Html.CheckBoxFor(model => model.Negotiable, new { @class = "form-control", @checked = "checked" })
        </span>
        @Html.TextBoxFor(model => model.Price, new { id = "price", @class = "form-control", })
    </div><!-- /input-group -->
</div><!-- /.col-lg-6 -->

But this is the result I get:

result

On the left you see a vertical grey thing which should have displayed a checkbox.

What am I missing?

1条回答
Evening l夕情丶
2楼-- · 2019-08-09 20:25

Given that the example HTML in your question is correct. Then this is the Razor equivalent of it.

Razor

<div class="col-lg-6">
    <div class="input-group">
        <span class="input-group-addon">
        @Html.CheckBoxFor(model => model.Negotiable, new { @checked = "checked" })
        </span>
        @Html.TextBoxFor(model => model.Price, new { id = "price", @class = "form-control", })
    </div><!-- /input-group -->
</div><!-- /.col-lg-6 -->

The difference is, I have removed the class form-control from @Html.CheckBoxFor as this is not required.

查看更多
登录 后发表回答