Home How to conditionally add CSS class to Html.TextBoxFor
Reply: 1

How to conditionally add CSS class to Html.TextBoxFor

Mukil Deepthi
1#
Mukil Deepthi Published in 2018-02-08 13:58:08Z

Can anyone help me how to add CSS class conditionally to Html.TextBoxFor in my razor view.

I am trying the following:

@Html.TextBoxFor(x => model.DateTimeStamp, new { @readonly = "readonly"}, ViewBag.IsNew ? (object)new {@class="test" }:null)
Nitesh
2#
Nitesh Reply to 2018-02-08 14:05:10Z

you can use like this..

@Html.TextBoxFor(x => model.DateTimeStamp, new { @readonly = "readonly", @class = ViewBag.IsNew ? "test" : "" })
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.529768 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO