Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add css class to Html.EditorFor in MVC 2

Tags:

c#

asp.net-mvc

I'm trying to add a css class to a textbox. This is what I have in my view:

<%: Html.EditorFor(m => m.StartDate) %> 

I tried following the instructions at this link by making my code:

<%: Html.EditorFor(m => m.StartDate, new { @class: "datepicker" }) %> 

But I get a compiler error saying:

Syntax error, ',' expected

What am I doing wrong here?

like image 404
Steven Avatar asked Jan 25 '11 02:01

Steven


1 Answers

With MVC3, I kept banging my head because I couldn't get this to work. I didn't want to create a whole EditorTemplate for just adding one class.

Well, instead of using EditorFor, use TextBoxFor, with of course the equals sign like so:

@Html.TextBoxFor(m=> m.ZipCode, new { @class = "zip" }) 
like image 176
Aaron Daniels Avatar answered Sep 22 '22 20:09

Aaron Daniels