You can create a partial class for your Model and add a metadata class to it. Then, you replicate your Model's properties in the metadata class and decorate them with your attributes.
Example:
[MetadataType(typeof(MyModelMetadata)]
public partial class MyModel
{
public class MyModelMetadata
{
[DisplayName("My property 1")]
[UIHint("SomeTemplate")]
public object MyModelProp1 {get; set; }
[DataType(DataTypes.PhoneNumber)]
public object MyModelProp1 {get; set; }
}
BTW, thanks for the great screencast. I loved the interview style as well. I was confused between LabelFor and DisplayFor. Very clear now
Hanselminutes on 9 - ASP.NET MVC 2 Preview 1 with Phil Haack and Virtual Scott
Dec 16, 2009 at 8:26 AM@cody.skidmore and @Mesfin:
You can create a partial class for your Model and add a metadata class to it. Then, you replicate your Model's properties in the metadata class and decorate them with your attributes.
Example:
[MetadataType(typeof(MyModelMetadata)]
public partial class MyModel
{
public class MyModelMetadata
{
[DisplayName("My property 1")]
[UIHint("SomeTemplate")]
public object MyModelProp1 {get; set; }
[DataType(DataTypes.PhoneNumber)]
public object MyModelProp1 {get; set; }
}
BTW, thanks for the great screencast. I loved the interview style as well. I was confused between LabelFor and DisplayFor. Very clear now
C# 4.0 New Features - Optional Parameters
Jun 18, 2009 at 12:21 PMCan someone provide a working video for this post? This one is broken!
Thanks!