我正在努力理解如何在 HtmlTargetElement 类属性中显示分配给 Attributes 的字符串。我有几个问题,我认为这将突出我的问题和理解。
假设我们只想在 make 以 gm 开头并且有任何模型时才激活 Html 元素。我认为有一种方法可以使用单个类属性(而不是多个)。
我正在尝试以下方法,但它只是一个 SWAG 并且不起作用。我很感激提示,这样我就可以理解文档说此属性可以采用“查询选择器如字符串”时的含义。
标签助手类
[HtmlTargetElement("auto-price", Attributes = "[make^=gm][model]")]
public class AutoPriceTagHelper : TagHelper
{
和剃刀标记
<auto-price make="gm" model="volt" ></auto-price>
<auto-price make="ford" model="mustang"></auto-price>
<auto-price make="ford" ></auto-price>
<auto-price test></auto-price>