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 8514953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:00:35+00:00 2026-06-11T05:00:35+00:00

I was writing up a controller action that creates a new user. Currently, the

  • 0

I was writing up a controller action that creates a new user. Currently, the controller action takes in the user entity model as a parameter.

I was wondering if I should pass values from the front-end in its own view model, and then extract values and create the entity in the backend?

public ActionResult AddUser(User user)
{
  context.Users.Add(user);
  context.SaveChanges();
}

vs

public ActionResult AddUser(UserViewModel userViewModel)
{
  var user = new User(userViewModel.Name);
  context.User.Add(user);
  context.SaveChanges();
}

Thanks!

  • 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-06-11T05:00:36+00:00Added an answer on June 11, 2026 at 5:00 am

    As with most things, there are multiple ways to do it. Ultimately in this case it often comes down to personal preference.

    When I’m doing this same thing, I often ask myself if what’s being passed into the method is actually a valid User at all. I like to keep my models in such a way that they internally prevent invalid states, rather than rely on the calling code to maintain validity of the model.

    As such, sometimes there are actions which receive information which describes a model but doesn’t fully construct a model by itself. In these cases, I prefer to use a view model. This often leads me to use view models across the board if for no other reason than consistency.

    It particularly comes in handy if I need information from more than one model on the page. Having a view model that’s a composite of the information I need rather than something like a Tuple of two models just feels cleaner to me. This also allows me to add additional properties to the view model (calculated fields, flags, etc.) that are useful to the view but would pollute the business object. (Switches to show/hide certain form elements, validation items, etc.)

    Often times you can find your own preference to this sort of question by noting the difference between an object (User) and a data structure (UserViewModel). In a traditional object-oriented sense, the User should hide its data members and provide an interface of functionality, whereas a flat data structure like UserViewModel would expose its data members and have no meaningful functionality.

    Since the view is just looking to bind to data members, I usually go with a flat view model instead of a domain object.

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

Sidebar

Related Questions

I'm writing my own sessions controller that issues a unique id to a user
I'm writing the spec for controller: it 'should call the method that performs the
I'm writing some unit tests to assert that all our controller action methods are
I'm writing a front-controller that will handle page requests, by parsing $_SERVER['REQUEST_URI']. I would
I am writing a view controller for adding a new item to my app.
I am writing a code for modbus protocol, that runs on a MSP430 controller.
I'm writing a controller helper that sets the proper response headers for my REST
I'm writing a spec for my Rails controller, this is the action I'm testing:
I am trying to secure a controller action that is being called with the
I am writing a Controller for Codeigniter with a method named print. The name

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.