Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 如何有条件地将CSS类添加到Html.TextBoxFor_Asp.net Mvc_Razor - Fatal编程技术网

Asp.net mvc 如何有条件地将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

谁能帮我在我的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 { @readonly = "readonly", @class = ViewBag.IsNew ? "test" : "" })