asp.net mvc 中编辑器模板中复杂类型的 ModelMetadata
我有一个视图模型,其中包含 TestThing 类型的复杂属性,该属性声明为:
public class TestThing
{
[Display(Name = "String3", Prompt = "String4")]
public string Test1 { get; set; }
[Display(Name = "String5", Prompt = "String6")]
public string Test2 { get; set; }
}
我有一个此类型的 EditorTemplate,我希望能够在其中访问每个子属性的元数据。例如,如果模板用于字符串,我可以使用 @ViewData.ModelMetadata.Watermark 访问提示文本,但因为它是复杂类型,所以我无法使用此方法。
还有其他选择吗?
I have a viewmodel that includes a complex property of type TestThing which is declared as:
public class TestThing
{
[Display(Name = "String3", Prompt = "String4")]
public string Test1 { get; set; }
[Display(Name = "String5", Prompt = "String6")]
public string Test2 { get; set; }
}
I have an EditorTemplate for this type in which I would like to be able to access the meta data for each of the child properties. If the template was for a string for example, I could access the Prompt text by using @ViewData.ModelMetadata.Watermark
, but because it is a complex type, I cannot use this method.
Is there an alternative?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以像这样获取每个属性的元数据:
You could fetch the metadata for each property like this:
1)检查一下。
1) Check this out.