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

删除回忆录丶 提交于 2019-12-07 19:34:39

问题


I want to show a glyphicon-user at the end of a textBoxFor control in MVC C# but I can't accomplished yet, in the code I show (razor commented @* *@) the span tags that I tried in order to get the glyphicon but didn't work out, could you please help me

            <div class="form-group">
                @Html.LabelFor(model => model.usuario, new { @class = "control-label col-md-2" })  
                <div class="col-md-10">
                    @*<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>*@

                    @Html.TextBoxFor(model => model.usuario, new { @class = "form-control", @placeholder = "Usuario", @type = "text" })
                    @*<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>*@
                    <p class="text-danger"> @Html.ValidationMessageFor(model => model.usuario)</p>
                </div>
            </div>

回答1:


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.



来源:https://stackoverflow.com/questions/42425271/add-a-glyphicon-user-to-a-textboxfor-control-in-mvc-asp-net

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