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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:31:02+00:00 2026-05-24T05:31:02+00:00

I think I get the idea of the ViewModel in MVC but, when doing

  • 0

I think I get the idea of the ViewModel in MVC but, when doing updates and deletes, it seems like there should be a distinct model for posting to the controller. I noticed the default razor controllers use ViewBag to hold Selectlists.

I guess that makes the ViewModel (domain entities really) reusable on the return trip because it is stripped of unnecessary data. But it seems like resorting to ViewBag doesn’t make sense when using view models because the view model can contain the Selectlists and such.

So my question is what kinds of patterns are there for making distinct “posted data” models? (got this term from Esposito’s MVC 2 book) And how should the posted data model be related to the view models? For example, it seems like I will try including the posted data models with the view models. I’m new to MVC and not coming from a web-forms background either. I would really like to understand the best patterns for modeling the data that will be sent to the controller.

  • 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-24T05:31:03+00:00Added an answer on May 24, 2026 at 5:31 am

    Often I use the same view model for passing it to the Edit/Update view and receiving it in the POST action. Here’s the commonly used pattern:

    public ActionResult Edit(int id)
    {
        DomainModel model = ... fetch the domain model given the id
        ViewModel vm = ... map the domain model to a view model
        return View(vm);
    }
    
    [HttpPost]
    public ActionResult Edit(ViewModel vm)
    {
        if (!ModelState.IsValid)
        {
            // there were validation errors => redisplay the view
            // if you are using dropdownlists because only the selected
            // value is sent in the POST request you might need to 
            // repopulate the property of your view model which contains
            // the select list items
            return View(vm);
        }
    
        DomainModel model = ... map the view model back to a domain model
        // TODO: process the domain model
    
        return RedirectToAction("Success")
    }
    

    As far as the mapping between the domain model and view models is concerned I would recommend you AutoMapper.

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

Sidebar

Related Questions

The idea here is to get better programmers right out of college. I think
I think i was doing halfway good to get this to halfway work. Anyways
I didn't find a solution for this but I think it should be doable.
I think I don’t quite get the idea behind the proper usage of Backbone
Perhaps I have been doing Flex development with Frameworks like Cairngorm too long but
i think you may get the idea of wat i'm trying to do if
I get the idea behind unit testing however am trying to think of a
I think I get the basics of multi-threading with Java. If I'm not mistaken,
OK I think I get Difference between jQuery.extend and jQuery.fn.extend? in that the general
I am new to sessions, and think I get the basics of them, they

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.