数据类型与 UiHint
我已经使用 mvc2 一段时间了,当我需要设置模板时,我使用 DataType 属性
<前><代码> [数据类型(“DropDown”)] 公共 int 字段 { 获取;放; }
我看到其他人使用 UiHint 来达到相同的结果
[UiHint("DropDown")] 公共 int 字段 { 获取;放; }
使用这两个属性有什么区别?我通常应该使用哪个属性,或者它们用于不同的任务?
I have been using mvc2 for a while now, and when i need to set the template i use the DataType Attribute
[DataType("DropDown")] public int Field { get; set; }
I see others using UiHint to achieve the same results
[UiHint("DropDown")] public int Field { get; set; }
What is the difference between using these two attributes? Which attribute should I be normally using, or are they for different tasks?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
DataType 通常用于表明这是属性的非常具体的版本,例如价格。
DataType 最常见的示例是
[DataType(DataTypes.EmailAddress)]
,它通常是一个字符串,但我们说这是一种非常特定的字符串类型。它们都很有帮助,并且 UIHint 覆盖 DataType。因此,如果您有特定的数据类型,但您想覆盖该特定属性的编辑器,则可以使用 UIHint。
DataType is generally used to make it known that this is a very specific version of a property, such as price.
The most common example of DataType is the
[DataType(DataTypes.EmailAddress)]
which usually is a string but we're saying that this is a very specific type of string.They're both helpful and the UIHint overrides the DataType. So if you have a certain DataType but you want to override the editor for that specific property you can use a UIHint.
DataType 属性有两个用途
UIHint的目的与上面第二点完全相同。
哪里用什么?答案是:上下文,即什么更有意义,什么更接近您的代码试图解决的物理问题。
如果两者都应用于同一个属性怎么办?答案是:显然 UIHint 具有优先权。但为什么要同时应用两者呢?
DataType attribute has two purposes
The purpose of UIHint is exactly same as the second point above.
Where to use what? The answer is: context, ie., what will make more sense, what is closer to the physical problem your code is trying to solve.
What if both are applied to the same property? The answer is: UIHint has precedence, obviously. But why would you apply both?