c# - 显示名称属性与显示属性

标签 c# asp.net-mvc data-annotations displayattribute .net-attributes

DisplayName 属性和 ASP.NET MVC 中的 Display 属性有什么区别?

最佳答案

DisplayName 在模型元数据中设置 DisplayName。例如:

[DisplayName("foo")]
public string MyProperty { get; set; }

如果您在 View 中使用以下内容:

@Html.LabelFor(x => x.MyProperty)

它会产生:

<label for="MyProperty">foo</label>

Display 的作用相同,但还允许您设置其他元数据属性,例如名称、描述...

Brad Wilson 有一个 nice blog post涵盖这些属性。

关于c# - 显示名称属性与显示属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13271067/

相关文章:

c# - 如何检查应用程序是否在任何屏幕上运行全屏模式?

c# - 学习 WCF 的基础知识

asp.net-mvc - 运行脚手架 Controller 时 MVC 3 脚手架错误

c# - 在数据注释的 ErrorMessage 属性中使用 html

asp.net-mvc - Asp.Net MVC : Some un-localized default error message?

validation - 为什么我的基于 DataAnnotations 的手动验证不起作用?

c# - Web API 2 中的版本控制

c# - 如何从文本文件创建 MD5 散列摘要?

c# - MVC Controller下的MVC Web Application项目

asp.net-mvc - 从 Asp.net core 中的日志记录中排除自定义异常类