Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to apply a Style to the Editor for an element, but I can't make it work; what am I doing wrong?

@Html.EditorFor(model => model.ClienteNuevo)
@Html.ValidationMessageFor(model => model.ClienteNuevo,"" ,new Dictionary<string,     string> { { "style", "width:500px" } })
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
177 views
Welcome To Ask or Share your Answers For Others

1 Answer

Since MVC 5.1, you can pass in custom attributes with using the htmlAttributes as a key:

@Html.EditorFor(model => model.ClienteNuevo, 
    new { htmlAttributes = new { @class = "form-control" } })

In older MVC versions there is no way to add html attributes with the EditorFor method.
You should create a custom editor template or use Html.TextboxFor istead of EditorFor. You should check these topics topic1, topic2.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...