0

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 { style = "width: 500px;" }).
Only problem is, I have another textbox (lets say random4) and it somehow overrides my DataAnnotation MultilineText and makes it a plain 500px textbox. Guess ill have to digg into the CSS :(

Kasper Skov
  • 1,954
  • 10
  • 32
  • 53

3 Answers3

1

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.

Community
  • 1
  • 1
Steve Morgan
  • 12,978
  • 2
  • 40
  • 49
  • Alright, thanks alot. Theres a bunch of different approches in that post, ill look them through and see if theres anything that fits me. – Kasper Skov Jul 26 '11 at 11:28
  • Wow, there is relativly a lot of effort in solving this reading though that post. You should think this was dead simple. – Kasper Skov Jul 26 '11 at 11:49
  • The issue is really down to the simplistic way in which the existing templates are defined. They're a simple 'starter for 10'. You can obtain or develop templates with richer functionality; the good thing is that they only need to be developed once, and you can use them over-and-over again. It's quite possible that later versions of MVC will have richer templates, but can you wait? – Steve Morgan Jul 26 '11 at 11:52
  • Nope :) Check out my update on the question. Any ideas on that? – Kasper Skov Jul 26 '11 at 11:59
0

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}

Kasper Skov
  • 1,954
  • 10
  • 32
  • 53
-1

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

stack72
  • 8,198
  • 1
  • 31
  • 35