Add css class to Html.EditorFor in MVC 2

前端 未结 8 1606
醉梦人生
醉梦人生 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" })
    

提交回复
热议问题