首页 > 解决方案 > How Can I add a dollar symbol in ASP.NET MVC5?

问题描述

How do I add a dollar symbol in front of a TextBox, which cannot be edited? I want to have the dollar symbol so people don't need to type '$' by themselves. Here is my code:

    @Html.Label("lblP1", "Rate 1", htmlAttributes: new { @class = "control-label", @style = "margin-right: 30px" })
<br />
@Html.EditorFor(m => m.Pricing.Price1, null, new { htmlAttributes = new { @type = "string", @class = "form-control" } })

Picture

标签: asp.net-mvcasp.net-mvc-5

解决方案


这是使用引导程序的示例:

<div class="input-group mb-3">
  <div class="input-group-prepend">
    <span class="input-group-text">$</span>
  </div>   
  @Html.EditorFor(m => m.Pricing.Price1, null, new { htmlAttributes = new { @type = "string", @class = "form-control" } })      
</div>

来源:https ://getbootstrap.com/docs/4.0/components/input-group/


推荐阅读