views:

120

answers:

2

Hi,

I'd like to change style of the 'editor for' textbox from MVC, specifically I want to make the textbox larger.

I've tried adding css a few ways, to no avail.

including :

<td class="myCss"><%=Html.EditorFor(x => x.NickName)%></td>

and <%=Html.EditorFor(x => x.NickName, new { @class = "myCss" })%>

help pls!

A: 

Try this

<%= Html.TextBoxFor(x => x.NickName, new { @class = "myCss" })%>

or

<%= Html.TextAreaFor(x => x.NickName, new { cols = "40%", @class = "myCss" })%>

Now you can define your attributes because MVC knows what type to use (TextArea).

rockinthesixstring
A: 

robh,

it's difficult to know from your question whether you're looking for a 'generic' or specific solution within your project. as such, i'm going to address the generic - works once, works everywhere solution.

this entails taking a few steps (convention over configuration). basically here's what's required:

  • create new folder under 'views->shared called Editor Templates'
  • create a new usercotrol (ascx) files under that called 'string.ascx'

now, define that ascx file as per:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<string>" %>
<div class="editor-label">
    <%= Html.LabelFor(model => model) %>
</div>
<div class="new-editor-field">
    <%= Html.TextBoxFor(model => model) %>
    <%= Html.ValidationMessageFor(model => model) %>
</div>

this will now make all 'string' based EditorFor() calls use this 'template'. simply make the class 'new-editor-field' reflect your desired css style for that field. obviously, cook as per your own requirement (i.e. you may not want the LabelFor tat etc..)

hope this helps - tho i have to say, this is just one of a few ways to do this (but is my prefered way).

enjoy

jim

jim