3

I have this code

<div class="input-group">
    <input type="text" class="form-control" name="InputName" id="InputName" placeholder="Enter Name" required>
    <span class="input-group-addon"><span class="glyphicon glyphicon-asterisk"></span></span>
</div>

how can I apply same span class to below line of code in razor?

@Html.TextBoxFor(m => m.Name,
                      new {
                            @class = "form-control",
                            @placeholder="Enter Name",
                            @requried="required"
                          }
                 )

Help will be appreciated.

Thank you

Abrar Jahin
  • 13,970
  • 24
  • 112
  • 161
banker box
  • 137
  • 2
  • 3
  • 10

2 Answers2

3

this should do it

<div class="form-group">
@*label if you have any*@
  <div class="input-group">
    @Html.TextBoxFor(m => m.Name,new {@class = "form-control",@placeholder="EnterName",@requried="required"})
   <span class="input-group-addon"><span class="glyphicon glyphicon-asterisk"></span></span>
  </div>
 </div>
Angloos
  • 755
  • 5
  • 11
1

Try this way

 <div class="input-group">
                              @Html.TextBoxFor(m => m.FirstName,
                              new
                              {
                                  @class = "form-control",
                                  @placeholder = "Enter Name",
                                  @requried = "required"
                              }

                         )
      <span class="input-group-addon"><span class="glyphicon glyphicon-asterisk">  </span></span>
</div>

Custom html helper is probably give a solution.

Check How can I override the @Html.LabelFor template?

and

Render span tag with title attribute with ASP.NET MVC 3 Helpers

Community
  • 1
  • 1
Nazmul Hasan
  • 10,130
  • 7
  • 50
  • 73