本文介绍了将 glyphicon-user 添加到 MVC ASP.NET 中的 TextBoxFor 控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 MVC C# 中的 textBoxFor 控件的末尾显示一个 glyphicon-user 但我还没有完成,在我显示的代码中(razor 评论了@* *@)我按顺序尝试的跨度标签得到字形但没有成功,你能帮我吗

 

@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)

解决方案

你已经接近了.您只是忘记包含一个 div 元素,其类名是 input-group.

@Html.LabelFor(model => model.usuario, new { @class = "control-label col-md-2" })<div class="col-md-10"><div class="input-group">//缺少 [email protected](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>

此外,您的 TextBoxFor 中也不需要这个.. @type = "text"

这里是 Bootply.

希望这会有所帮助.

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>
解决方案

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.

这篇关于将 glyphicon-user 添加到 MVC ASP.NET 中的 TextBoxFor 控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 07:50