Add css class to Html.EditorFor in MVC 2

前端 未结 8 1597
醉梦人生
醉梦人生 2020-12-05 09:57

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 follo

相关标签:
8条回答
  • 2020-12-05 10:22

    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" })
    
    0 讨论(0)
  • 2020-12-05 10:22

    Here's a very simple solution: Remove the double quotes from "datepicker" and retype them back into Visual Studio and it should work.

    I had the same problem. I copied/pasted sample code from the web and the code had a special type of quote which caused the "," syntax problem. I know it's really not obvious.

    0 讨论(0)
提交回复
热议问题