【发布时间】:2016-08-29 07:43:47
【问题描述】:
ASP.NET Core 引入了自定义标签助手,可以在如下视图中使用:
<country-select value="CountryCode" />
但是,我不明白如何在我的类中获取模型属性名称:
public class CountrySelectTagHelper : TagHelper
{
[HtmlAttributeName("value")]
public string Value { get; set; }
public override void Process(TagHelperContext context, TagHelperOutput output)
{
...
// Should return property name, which is "CountryCode" in the above example
var propertyName = ???();
base.Process(context, output);
}
}
在以前的版本中,我可以通过使用ModelMetadata 来做到这一点:
var metadata = ModelMetadata.FromLambdaExpression(expression, html.ViewData);
var property = metadata.PropertyName; // return "CountryCode"
如何在新的ASP.NET 标签助手中做同样的事情?
【问题讨论】:
-
你为什么不使用
Value属性?
标签: asp.net-mvc razor asp.net-core tag-helpers