Asp.net mvc 如何有条件地将CSS类添加到Html.TextBoxFor
谁能帮我在我的razor视图中将CSS类有条件地添加到Html.TextBoxFor中 我正在尝试以下方法:Asp.net mvc 如何有条件地将CSS类添加到Html.TextBoxFor,asp.net-mvc,razor,Asp.net Mvc,Razor,谁能帮我在我的razor视图中将CSS类有条件地添加到Html.TextBoxFor中 我正在尝试以下方法: @Html.TextBoxFor(x => model.DateTimeStamp, new { @readonly = "readonly"}, ViewBag.IsNew ? (object)new {@class="test" }:null) 你可以这样用 @Html.TextBoxFor(x => model.DateTimeStamp, new { @readon
@Html.TextBoxFor(x => model.DateTimeStamp, new { @readonly = "readonly"}, ViewBag.IsNew ? (object)new {@class="test" }:null)
你可以这样用
@Html.TextBoxFor(x => model.DateTimeStamp, new { @readonly = "readonly", @class = ViewBag.IsNew ? "test" : "" })