C# 在ASP.NET MVC中使用Razor时,如何向单选按钮添加类
我想在下面的单选按钮中添加一个名为locationFilter的类?当我使用剃须刀时,我该怎么做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"]);
@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" }
几句话:
- 之所以有@符号,是因为
是C#中的一个关键字,所以语言会认为您引用了它。通过使用@,您基本上告诉编译器不要将其理解为关键字,而是将其理解为普通属性名class
- 您可以在此匿名类型中添加更多HTML属性,例如,如果需要输出
,只需在匿名类型的构建块中添加逗号和title
title=“something”
@Html.RadioButton("plantFilter", "IL", (bool)@TempData["MN"], new { @class = "yourclass" });
您必须以新的匿名类型传入一个附加参数(您可以在IntelliSense中看到它,名称为
htmlAttributes
):
new { @class = "yourclass" }
几句话:
- 之所以有@符号,是因为
是C#中的一个关键字,所以语言会认为您引用了它。通过使用@,您基本上告诉编译器不要将其理解为关键字,而是将其理解为普通属性名class
- 您可以在此匿名类型中添加更多HTML属性,例如,如果需要输出
,只需在匿名类型的构建块中添加逗号和title
title=“something”
@Html.RadioButton("plantFilter", "IL", (bool)@TempData["MN"], new { @class = "yourclass" });
RadioButton helper方法将htmlAttributes
作为参数。您可以在其中指定所需的内容。请参阅
RadioButton helper方法将htmlAttributes
作为参数。您可以在其中指定所需的内容。请参阅