Define a seperate ViewModel for EditProfile View or use the User model (DRY vs convenience)
For my Edit Profile page, all the items are from the User entity. Things like email, password, fullname, city, etc. I'm using ASP .NET MVC2 along with Entity Framework 4. I'm wondering if I should create a separate ProfileModel for my EditProfile View or if I should just use the User entity created by EF. My dilemmna is that if I created a ProfileModel, then I would be repeating myself (as all the properties are already in the User model), but on the other hand if I use the User model, then I'm not sure how I can add attributes (like [DisplayName("Password")]) since the User model is auto-generated.
I realize that the AccountModels that ship with MVC do define separate models that repeat fields l开发者_Go百科ike Password and Username that are already in User.
You can (and should) add validation attributes for your existing entity classes using a 'buddy class'. See this post by ScottGu and search on the page for "buddy class" to find specifics:
http://weblogs.asp.net/scottgu/archive/2010/01/15/asp-net-mvc-2-model-validation.aspx
精彩评论