如何设置html.EditorFor helper的大小?

时间:2022-09-26 21:08:10

What is the simplest way to set the size of the generated field?

设置生成字段大小的最简单方法是什么?

2 个解决方案

#1


15  

Using CSS:

使用CSS:

<div class="foo">
    <%= Html.EditorFor(x => x.Foo) %>
</div>

and in your CSS file:

并在您的CSS文件中:

.foo input {
    width: 200px;
}

You could also implement a custom DataAnnotationsModelMetadataProvider which would allow you to attach any attributes you like to the generated input field such as class, maxlength, size, ...

您还可以实现自定义DataAnnotationsModelMetadataProvider,它允许您将任何您喜欢的属性附加到生成的输入字段,例如class,maxlength,size,...

#2


6  

Another option still: rather than appending the class to the wrapper around your input, you can apply HTML properties to the input itself (doesn't work for "EditorFor" though):

另一个选择是:不是将类附加到输入的包装器,而是可以将HTML属性应用于输入本身(但不适用于“EditorFor”):

@Html.TextBoxFor(x => x.Foo, new { @class = "bar" })

Further discussion: http://michaelware.net/post/2010/01/31/Custom-Attributes-When-Using-HtmlTextBoxFor.aspx

进一步讨论:http://michaelware.net/post/2010/01/31/Custom-Attributes-When-Using-HtmlTextBoxFor.aspx

#1


15  

Using CSS:

使用CSS:

<div class="foo">
    <%= Html.EditorFor(x => x.Foo) %>
</div>

and in your CSS file:

并在您的CSS文件中:

.foo input {
    width: 200px;
}

You could also implement a custom DataAnnotationsModelMetadataProvider which would allow you to attach any attributes you like to the generated input field such as class, maxlength, size, ...

您还可以实现自定义DataAnnotationsModelMetadataProvider,它允许您将任何您喜欢的属性附加到生成的输入字段,例如class,maxlength,size,...

#2


6  

Another option still: rather than appending the class to the wrapper around your input, you can apply HTML properties to the input itself (doesn't work for "EditorFor" though):

另一个选择是:不是将类附加到输入的包装器,而是可以将HTML属性应用于输入本身(但不适用于“EditorFor”):

@Html.TextBoxFor(x => x.Foo, new { @class = "bar" })

Further discussion: http://michaelware.net/post/2010/01/31/Custom-Attributes-When-Using-HtmlTextBoxFor.aspx

进一步讨论:http://michaelware.net/post/2010/01/31/Custom-Attributes-When-Using-HtmlTextBoxFor.aspx