Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.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
C# Html.DropDownList的验证和htmlAttributes参数_C#_Validation_Webmatrix_Asp.net Webpages - Fatal编程技术网

C# Html.DropDownList的验证和htmlAttributes参数

C# Html.DropDownList的验证和htmlAttributes参数,c#,validation,webmatrix,asp.net-webpages,C#,Validation,Webmatrix,Asp.net Webpages,下面允许您指定一个htmlAttribute,以获得添加到项目的其他html属性 不工作:仍然为空 string className = Validation.ClassFor("vehicleId").ToString(); var htmlAttributes = new { id = "vehicleSelectControl", style = "font-size:24px;", @cla

下面允许您指定一个htmlAttribute,以获得添加到项目的其他html属性

不工作:仍然为空

string className = Validation.ClassFor("vehicleId").ToString();
var htmlAttributes = new { id = "vehicleSelectControl", 
                        style = "font-size:24px;",
                        @class = className
                        };
不起作用:仍然为空,不应为空

string className = (String.IsNullOrEmpty(Validation.ClassFor("vehicleId").ToString())) ? "" : Validation.ClassFor("vehicleId").ToString();

var htmlAttributes = new { id = "vehicleSelectControl", 
                        style = "font-size:24px;",
                        @class = className
                        };
我应该放弃,还是有办法通过验证来设计我的样式

var htmlAttributes = new { id = "vehicleSelectControl", 
                        style = "font-size:24px;",
                        @class = Validation.ClassFor("vehicleId").ToString()
string className = Validation.ClassFor("vehicleId").ToString();
var htmlAttributes = new { id = "vehicleSelectControl", 
                        style = "font-size:24px;",
                        @class = className
                        };
string className = (String.IsNullOrEmpty(Validation.ClassFor("vehicleId").ToString())) ? "" : Validation.ClassFor("vehicleId").ToString();

var htmlAttributes = new { id = "vehicleSelectControl", 
                        style = "font-size:24px;",
                        @class = className
                        };