Twitterbootstrap input-groups with Razor syntax

匆匆过客 提交于 2020-01-05 09:29:27

问题


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:

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

What am I missing?


回答1:


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.



来源:https://stackoverflow.com/questions/26449580/twitterbootstrap-input-groups-with-razor-syntax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!