Basically, I have a table with multiple editors like this:
<table>
<tr>
<td>@Html.EditorFor(x => x.Random1)</td>
<td>@Html.EditorFor(x => x.Random2)</td>
</tr>
<tr>
<td colspan="2">@Html.EditorFor(x=> x.Random3)</td>
</tr>
</table>
Now, my problem is, as you probably already figured out from the colspan="2", is that I want my third textbox to stretch all the way thorugh the two columns. In normal HTML is would naturally just add a width attribute. Is there a DataAnnotation like DataType.MultilineText
that can change the width of the editors? Any other ideas?
UPDATE: If I change it to a TextBoxFor instead of EditorFor, I can actually add @Html.TextBoxFor(x => x.Random, new { 开发者_如何学JAVAstyle = "width: 500px;" })
.
You might find some of the answers to this question useful.
The good thing about templates is that if you don't like the way they work, you can simply drop-in your own implementation.
You can also try using CSS to specify the width for your control, based on it's ID.
Easiest solution is to just style the control in the css. For the random3 textbox ill use input[type="text"]{width:1px}
and for the random4 multilinetext, ill use just use textarea{width:1px}
In the Property of the Model - in this case Random3 give it an annotation
public class ViewModelName
{
[DataType(DataType.MultilineText)]
public string Random3 { get; set; }
}
then when you can the Html.EditorFor(x => x.Random3) it will know it needs to be multiline
精彩评论