Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
1 down vote

favorite





I am having trouble with what should be a very simple task. I'm trying to map values retrieved from a database to a view model. I then want to pass that as the model to my view.

The view model is called EditAdminModelVM and it contains a smaller subset of properties from a larger class called UserProfile. I chose to use a view model because I do not want the user to be able to update the whole domain model, only a few from it.

Here is the ViewModel:
C#
public class EditAdminModelVM
{
    [Required]
    [StringLength(50, ErrorMessage = "The {0} must be at least {2} characters long.")]
    [Display(Name = "First name")]
    public string FirstName { get; set; }

    [Required]
    [StringLength(50, ErrorMessage = "The {0} must be at least {2} characters long.")]
    [Display(Name = "Last name")]
    public string LastName { get; set; }

    [Required]
    [MaxLength(250)]
    [EmailAddress]
    public string Email { get; set; }

    [Required]
    //[Remote("doesUserNameExist", "Account", HttpMethod = "POST", ErrorMessage = "Username already exists. Please enter a different User Name.")] //note this checks from client-side only - server side check is built in to membership
    [Display(Name = "Username")]
    public string UserName { get; set; }

    [HiddenInput]
    public int UserId { get; set; }
Posted
Comments
stibee 30-Jul-15 5:05am    
I'm not shure what you like to do...
Where do you create your model? Maybe a constructor which takes the object from the db will help you.
[no name] 31-Jul-15 0:36am    
Let us see your controller and view code?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900