Reputation: 6492
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
Reputation: 1774
you can use like this..
@Html.TextBoxFor(x => model.DateTimeStamp, new { @readonly = "readonly", @class = ViewBag.IsNew ? "test" : "" })
Upvotes: 1