Mukil Deepthi
Mukil Deepthi

Reputation: 6492

How to conditionally add CSS class to Html.TextBoxFor

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)

Upvotes: 0

Views: 1502

Answers (1)

Nitesh Kumar
Nitesh Kumar

Reputation: 1774

you can use like this..

@Html.TextBoxFor(x => model.DateTimeStamp, new { @readonly = "readonly", @class = ViewBag.IsNew ? "test" : "" })

Upvotes: 1

Related Questions