MVC 2 EditorForModel 指定生成输入的宽度
我在视图中使用 Html.EditorForModel()
来生成编辑表单的字段。我还有另一个部分类,我在其中为某些字段指定一些数据注释属性(如 DisplayName、Range 等)。
当我运行该应用程序时,我为每个字段生成了 HTML 输入。如何指定生成的输入的宽度?
像这样的东西:
<input id="nameTextBox" style="width:220px" name="theName" />
I use the Html.EditorForModel()
in a view to generate fields for the edit form. I also have another partial class where I specify some Data Annotation attributes for some fields (like DisplayName, Range etc).
When I run the application I have HTML inputs generated for each field. How can I specify the width of this generated inputs ?
Something like this:
<input id="nameTextBox" style="width:220px" name="theName" />
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
@Gerrie 的解决方案有效,但它适用于页面上的所有输入。如果您不想以这种方式设置页面上的其他输入,那么您可以执行以下操作:
然后使用以下形式的 CSS:
编辑
如果您想设置 CSS 规则对于个别领域,您也可以这样做。检查生成的 HTML 并找到输入的
id
,然后执行以下操作:@Gerrie's solution works, but it applies to all inputs on the page. If you have other inputs on the page that you don't want to style this way, then you can do something like this:
And then use CSS of this form:
EDIT
If you want to set CSS rules for individual fields, you can do so too. Inspect the generated HTML and find the input's
id
, then do:使用 CSS:
这样您就不必费心将这些样式属性插入到生成的控件中。
use CSS:
This way you don't have to bother about inserting these style attributes into the generated controls.