Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/335.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.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# 在ASP.NET MVC中使用Razor时,如何向单选按钮添加类_C#_Asp.net Mvc_Razor - Fatal编程技术网

C# 在ASP.NET MVC中使用Razor时,如何向单选按钮添加类

C# 在ASP.NET MVC中使用Razor时,如何向单选按钮添加类,c#,asp.net-mvc,razor,C#,Asp.net Mvc,Razor,我想在下面的单选按钮中添加一个名为locationFilter的类?当我使用剃须刀时,我该怎么做 @Html.RadioButton("plantFilter", "ALL", (bool)@TempData["ALL"]) @Html.RadioButton("plantFilter", "IL", (bool)@TempData["MN"]); @Html.RadioButton("plantFilter", "NY", (bool)@TempData["BP"]);

我想在下面的单选按钮中添加一个名为locationFilter的类?当我使用剃须刀时,我该怎么做

   @Html.RadioButton("plantFilter", "ALL", (bool)@TempData["ALL"])
   @Html.RadioButton("plantFilter", "IL", (bool)@TempData["MN"]); 
   @Html.RadioButton("plantFilter", "NY", (bool)@TempData["BP"]); 
   @Html.RadioButton("plantFilter", "CA", (bool)@TempData["MT"]); 

您必须以新的匿名类型传入一个附加参数(您可以在IntelliSense中看到它,名称为
htmlAttributes
):

new { @class = "yourclass" }
几句话:

  • 之所以有@符号,是因为
    class
    是C#中的一个关键字,所以语言会认为您引用了它。通过使用@,您基本上告诉编译器不要将其理解为关键字,而是将其理解为普通属性名
  • 您可以在此匿名类型中添加更多HTML属性,例如,如果需要输出
    title
    ,只需在匿名类型的构建块中添加逗号和
    title=“something”
代码的精确示例:

@Html.RadioButton("plantFilter", "IL", (bool)@TempData["MN"], new { @class = "yourclass" });

您必须以新的匿名类型传入一个附加参数(您可以在IntelliSense中看到它,名称为
htmlAttributes
):

new { @class = "yourclass" }
几句话:

  • 之所以有@符号,是因为
    class
    是C#中的一个关键字,所以语言会认为您引用了它。通过使用@,您基本上告诉编译器不要将其理解为关键字,而是将其理解为普通属性名
  • 您可以在此匿名类型中添加更多HTML属性,例如,如果需要输出
    title
    ,只需在匿名类型的构建块中添加逗号和
    title=“something”
代码的精确示例:

@Html.RadioButton("plantFilter", "IL", (bool)@TempData["MN"], new { @class = "yourclass" });
RadioButton helper方法将
htmlAttributes
作为参数。您可以在其中指定所需的内容。请参阅

RadioButton helper方法将
htmlAttributes
作为参数。您可以在其中指定所需的内容。请参阅