【问题标题】:Form Input Syntax In RAZORRAZOR 中的表单输入语法
【发布时间】:2016-05-08 01:03:42
【问题描述】:

我有这个代码

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

如何将相同的跨度类应用于剃须刀中的以下代码行?

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

我们将不胜感激。

谢谢

【问题讨论】:

    标签: asp.net-mvc-4 razor


    【解决方案1】:

    应该这样做

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

    【讨论】:

      【解决方案2】:

      试试这个方法

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

      自定义 html 助手可能是一个解决方案。

      查看How can I override the @Html.LabelFor template?

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

      【讨论】:

      • 它足够接近,但字形星号没有正确对齐。谢谢你的帮助
      猜你喜欢
      • 1970-01-01
      • 2014-06-14
      • 1970-01-01
      • 2014-12-14
      • 2017-04-06
      • 2017-11-06
      • 2018-07-06
      • 1970-01-01
      • 2021-09-08
      相关资源
      最近更新 更多