Html 将类添加到TextBoxFor

Html 将类添加到TextBoxFor,html,css,entity-framework,bootstrap-4,Html,Css,Entity Framework,Bootstrap 4,如何将表单控件类添加到此TextBoxFor?我不熟悉编码 小时 @TextBoxFor(model=>model.hours,new{type=“number”,min=“0”,step=“1”,htmlAttributes=new{@class=“form control center block”}) @Html.ValidationMessageFor(model=>model.hours,“,new{@class=“text danger”}) 不确定htmlAttributes从

如何将表单控件类添加到此TextBoxFor?我不熟悉编码


小时
@TextBoxFor(model=>model.hours,new{type=“number”,min=“0”,step=“1”,htmlAttributes=new{@class=“form control center block”})
@Html.ValidationMessageFor(model=>model.hours,“,new{@class=“text danger”})

不确定
htmlAttributes
从何而来,但您已经在该对象中设置HTML属性的上下文中,例如
类型
最小值
步骤
。您还在
验证消息中为
设置
@class
,为什么不应用相同的标准

只需删除
htmlAttributes
,并在具有其他属性的对象上设置
@class
属性:

@Html.TextBoxFor(
  model => model.hours,
  new {
    type = "number",
    min = "0",
    step = "1",
    @class = "form-control center-block"
  })

这回答了你的问题吗?