【发布时间】:2017-03-18 01:31:53
【问题描述】:
我正在努力理解如何在 HtmlTargetElement 类属性中显示分配给属性的字符串。我有几个问题我认为会突出我的问题和理解。
假设我们只想在 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>
【问题讨论】:
标签: c# asp.net-core asp.net-core-mvc asp.net-core-tag-helpers