我有一个文本框,我在其中设置类属性 css rounded
。
我使用这段代码:
@Html.TextBoxFor(m => m.level, new { @class = "form-control rounded", @placeholder = "Level" })
当我运行浏览器渲染器时:
<input class="form-control rounded" id="level" name="level" placeholder="Level" type="text" " />
如果我改为:
@Html.EditorFor(m => m.level, new { @class = "form-control rounded", @placeholder = "Level" })
浏览器rederizer为:
<input class="text-box single-line" id="level" name="level" placeholder="Level" />
有一种方法可以将rounded
与@Html.EditorFor
一起使用吗?
使用@Html.EditorFor
有什么好处?
最佳答案
TextBoxFor:它会呈现与指定表达式对应的文本输入 html 元素。简而言之,无论与控件绑定(bind)的属性的数据类型如何,它总是像输入文本框一样呈现。
EditorFor:这个控件有点聪明。它根据属性的数据类型呈现 HTML 标记。例如。假设模型中有一个 bool 属性。要在 View 中将此属性呈现为复选框,我们可以使用 CheckBoxFor 或 EditorFor。两者都将生成相同的标记。
使用 EditorFor 有什么好处?
正如我们所知,它根据属性的数据类型生成 html 标记。所以假设明天如果我们更改模型中属性的数据类型,则无需更改 View 中的任何内容。 EditorFor 控件将自动更改 html 标记。
关于html - @Html.EditorFor 中的属性 css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38019898/