Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6130453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:51:37+00:00 2026-05-23T16:51:37+00:00

I am trying to create a view model for editing which contains some slightly

  • 0

I am trying to create a view model for editing which contains some slightly different fields then the main model, however it appears when trying to render a view for this view model it throws and exception because some properties are missing that are specified in the MetadataType.

Code:

[MetadataType(typeof(IAdministrator))]
    public partial class Administrator : IAdministrator
    {
        public string Name { get { return String.Format("{0} {1}", FirstName, LastName); } }
    }

    [MetadataType(typeof(IAdministrator))]
    public class AdministratorEdit
    {
        public int AdministratorID { get; set; }

        public string EmailAddress { get; set; }

        public string FirstName { get; set; }

        public string LastName { get; set; }

        [DisplayName("New Password")]
        [DataType(DataType.Password)]
        [StringLength(12, MinimumLength = 8)]
        public string NewPassword { get; set; }

        [DisplayName("Re-New Password")]
        [DataType(DataType.Password)]
        [StringLength(12, MinimumLength = 8)]
        public string ReNewPassword { get; set; }
    }

    public interface IAdministrator
    {
        [Required]
        [DisplayName("Email Address")]
        [DataType(DataType.EmailAddress)]
        [RegularExpression(@"^(([\w-]+\.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2,}))@((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|([a-zA-Z]+[\w-]+\.)+[a-zA-Z]{2,4})$")]
        [StringLength(320)]
        string EmailAddress { get; set; }

        [Required]
        [DisplayName("Password")]
        [DataType(DataType.Password)]
        [StringLength(12, MinimumLength = 8)]
        string Password { get; set; }

        [Required]
        [DisplayName("First Name")]
        [DataType(DataType.Text)]
        [StringLength(25)]
        string FirstName { get; set; }

        [Required]
        [DisplayName("Last Name")]
        [DataType(DataType.Text)]
        [StringLength(25)]
        string LastName { get; set; }

        [DisplayName("Date Created")]
        [DataType(DataType.Date)]
        DateTime Date { get; set; }
    }

This is the exception that I get from the view which uses the AdministratorEdit model:
The associated metadata type for type ‘….Models.AdministratorEdit’ contains the following unknown properties or fields: Password, Date. Please make sure that the names of these members match the names of the properties on the main type.

Can someone please sugest another method of creating a view model without having to specify another MetadataType or just a quick fix for this exception?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:51:37+00:00Added an answer on May 23, 2026 at 4:51 pm

    From your IAdminstrator interface you could extract a base class (interface), the base interface would just have the edit fields (IAdministratorEdit) and IAdministrator would remain with all fields, as it would inherit from the IAdministratorEdit.

    public interface IAdministrator : IAdministratorEdit 
    

    and then just use the IAdministratorEdit interface on your ViewModel. That way you only have to define the constraints in you metadata once.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to create a list to return some JSON data to a view. Following
In a view I'm trying to create a new user and then log them
I'm trying to create a view that contains a list of checkboxes that is
I'm trying to create an MVC view that will display some data in a
I am trying to create a multi step form using model classes: my view:
I have a complex view model which contains a collection of other objects which
I'm trying to create a strongly typed view model as John Sheehan suggests here
I'm currently trying to create a view in asp.net MVC2 which includes a checkbox
I'm trying to create a tabpanel view that contains a splitview controller on the
I am trying to create a view for a UNION of 2 select statements

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.