1

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 ?

2

2 Answers 2

1

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

4
  • I looked from following sample msdn.microsoft.com/en-us/library/… Sep 26, 2012 at 9:18
  • Updated my answer. Please don't forget to mark the answer as accepted once your question is resolved. Thanks Sep 26, 2012 at 17:57
  • 1
    Upped your response instead of repeating your response. Nov 1, 2013 at 20:07
  • @MuhammadImran Why not mark answer is right one (its been a year)? Thanks Nov 2, 2013 at 15:45
0

object AspUserName != string AspUserName

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.