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

  • Home
  • SEARCH
  • 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 7696729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:50:51+00:00 2026-05-31T21:50:51+00:00

I am developing a ASP.NET MVC 3 application, i am using entity framework code

  • 0

I am developing a ASP.NET MVC 3 application, i am using entity framework code first in order to create the classes of my app, and i also have a repository in order to perform the operations on it, keeping clean the DBContext and the DBEntities definitions.

My doubt is about the render of the views and the way where a edit model is saved.

If I have this entity that represent a user stored in my DB:

//Entity:
public class User 
{
    [Key]
    public int IdUser { get; set; }
    public string UserName { get; set; }   
    public string Password { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Email { get; set; }
}

And i want to show a View with the FirstName, LastName, Email and NewPassword, ConfirmPasword and CurrentPassword, in order to let the user change his data, typing the CurrentPassword to confirm the changes, so my doubt is, fieds like ConfirmPasword and CurrentPassword aren´t in my entity so i need to create a new model for this View and the copy the information that i want from my new Model to my database entity in order to save it? Like:

public class UpdateUserModel
{

    [Required]
    [Display(Name = "Name")]
    public string FirstName{ get; set; }

    [Required]
    [Display(Name = "Last Name")]
    public string LastName{ get; set; }

    [Required]
    [DataType(DataType.EmailAddress)]
    [Display(Name = "Not valid email")]
    public string Email { get; set; }      

    [DataType(DataType.Password)]
    [Display(Name = "New password")]
    public string NewPasword{ get; set; }

    [DataType(DataType.Password)]
    [Display(Name = "Confirm the New Pasword")]
    [Compare("NewPasword", ErrorMessage = "Password doesn´t mach.")]
    public string ConfirmPasword{ get; set; }

    [Required(ErrorMessage = "Need to specify the current password to save changes")]
    [DataType(DataType.Password)]
    [Display(Name = "Current Password")]
    public string CurrentPassword { get; set; }
}

and in the controller i made:

public ActionResult UpdateUser(UpdateUserModel model)
{              
    User u = (User)Membership.GetUser();            
    u.FirstName = model.FirstName;
    u.LastName = model.LastName;
    u.Email = model.Email;

    if (!String.IsNullOrEmpty(model.NewPassword))
    {
        u.Password = FormsAuthentication.HashPasswordForStoringInConfigFile(model.NewPassword.Trim(), "md5");
    }

    repository.UpdateUser(u);

    return View();
}

There are any way of doing this having a controller like:

public ActionResult UpdateUser(User u)
{               
    repository.UpdateUser(u);              
    return View();
}

Because if i have that, how i can add the field like, ConfirmPassword or CurrentPassword in order to made the validation for this specific View.

  • 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-31T21:50:53+00:00Added an answer on May 31, 2026 at 9:50 pm

    If I were you, I wouldn’t use domain model in my presentation layer. I would create a view model (another class) which will be very similar to my domain model. I would then use auto-mapping tool to map from my domain model to the view model.

    This is a very common scenario, so if you Google for “view and domain” models you should find everything you need.

    public class User {
            [Key]
            public int IdUser { get; set; }
            public string UserName { get; set; }   
            public string Password { get; set; }
            public string FirstName { get; set; }
            public string LastName { get; set; }
            public string Email { get; set; }
    
    }
    
    public class UpdateUserViewModel {
        // Original fields
    
        public string Password  { get; set; }
    
        public string PasswordConfirmation { get; set;
    }
    

    You could then configure auto-mapper to remove your boiler plate code:

    public ActionResult ShowUser()
    {
        var domainModel = new User(); // I'm assuming that properties are set somewhere
        var viewModel = new UserViewModel();  
    
        Autommaper.Map(domainModel, viewModel);
    
        return View(viewModel);
    }
    

    This is very rough, but hopefully you get an idea.

    Update 1: **

    As i understood is better to create a new model for each view and then map it into the entity

    It’s not just better, it provides better separation of concerns, makes your code easily testable. Just by looking at the name of the class, I can see its purpose UpdateUserViewModel, RegisterUserViewModel etc).

    Original fields, in this class is supposed to be the Metadata with the validation and that stuff isn’t?

    By original fields I mean:

    public class UserViewModel{
       public string UserName { get; set; }
       public string FirstName { get; set; }
    
    }
    

    These fields are already in your User class, so I saved my time by not typing them in again.

    This will be change my model from MVC to MVVM or not beacuse i still have a controller?

    I believe what I’ve suggested is still an MVC pattern, rather than MVVM.

    About the Automaper, are you using github.com/AutoMapper/AutoMapper?

    Automapper is something that I have used. There are few tools out there and they do pretty much the same thing. Try out few and find one that suits your requirements the most.

    Good luck.

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

Sidebar

Related Questions

I'm developing a web application using ASP.NET MVC 3 and Entity Framework Code First
I am developing an ASP.Net MVC 3 Web application using Entity Framework 4.1 and
I am developing an ASP.Net MVC 3 Web application using Entity Framework 4.1, however,
I am developing an ASP.Net MVC 3 Web application using Entity Framework 4.1. I
I am developing a medium sized ASP.NET project using ASP.NET MVC and Entity Framework.
I am developing a web application using Asp.net mvc framework with concept of sub
I'm developing a web application using ASP.NET MVC (I'm new to the framework and
I am developing my first web application using ASP.Net MVC, and I am in
I'm developing a web app in asp.net mvc using jquery, the language of application
I am developing a application for Sales Order Management using ASP.NET MVC 3.0. I

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.