user948365
user948365

Reputation:

MVC 4 Data Annotations

I am using Data Annotations in my MVC 4 project with Scaffolding Nuget to create CRUD views. I am using Layer level Database model not EF.

So my Class look like as below:

[MetadataType(typeof(CustomerMetaData))] 
public partial class UserProfile: IBrObject
{
     public UserProfile(string aspUserName): this()
        {
            this.AspUserName = aspUserName;
        }

     public string AspUserName { get; set; }
     public DateTime MetaDateFirstSaved { get; set; }
}

public class CustomerMetaData
{
            [ReadOnly(true)]             
            [ScaffoldColumn(false)]
            [DisplayName("ASP UserName")]
            public object AspUserName { get; set; }
           [DisplayName("Date First Saved")]
           [DataType(DataType.Date)]
            public object MetaDateFirstSaved { get; set; }
}

when i am trying to create views with Scaffolding Nuget it still shows AspUserName column not hide or not read only. How i can hide or readonly ?

Upvotes: 1

Views: 2055

Answers (2)

Display Name
Display Name

Reputation: 4732

You use object in metadata and string and DateTime respectively in actual view model so they don't match.

Update

Another possibility (I pretty sure this is what's happening in your case) is because your model type in the view defined as Interface type rather than class type.

In your view replace @model IBrObject with @model UserProfile.

Hope this helps

Upvotes: 1

Code Monkey
Code Monkey

Reputation: 643

object AspUserName != string AspUserName

Upvotes: 0

Related Questions