add a glyphicon-user to a TextBoxFor control in MVC ASP.NET

会有一股神秘感。 提交于 2019-12-06 16:05:17

You are close. You just forgot to include a div element with the class name input-group.

<div class="form-group">
    @Html.LabelFor(model => model.usuario, new { @class = "control-label col-md-2" })
    <div class="col-md-10">  
        <div class="input-group"> // missing div 
            @Html.TextBoxFor(model => model.usuario, new { @class = "form-control", @placeholder = "Usuario" })
            <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
            <p class="text-danger">@Html.ValidationMessageFor(model => model.usuario)</p>
        </div>
    </div>
</div>

Also you don't need this in your TextBoxFor.. @type = "text"

Here is Bootply.

Hopefully this helps.

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