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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:45:54+00:00 2026-05-18T08:45:54+00:00

The pattern I see in the majority of .NET MVC examples is to have

  • 0

The pattern I see in the majority of .NET MVC examples is to have your model be the object passed between the controller and lower layers and to form-bind directly to those. I opted for a domain-driven approach where I have domain objects passed between the layers. The idea was that these objects would be passed into the views.

The problem I’m running into is when it comes to pages with forms. I was intending to have separate objects for the forms to bind to on the way back (which would also contain the validation annotations). I was keeping that separate from the domain object because a single object could possibly be updated by different pages, with each page having it’s own validation requirements (for example a person’s address might not even be shown on one page, but required on another, so the validation wouldn’t always work on the universal domain object). This complicates things once you postback the form and need to display errors.

Take for example an update page. I’d type the view to my domain Person object and the page would have it’s field values populated from that. The postback action would take the form object for that page and validate that. If it passed I use automapper to copy the values to the domain object off the form and save. This all works. Where it breaks down is re-displaying that page when there are errors. If it’s typed to the domain object I’d end up just repopulating the fields based on the old values instead of the values the user entered. If it’s typed to the form object then I need to translate all my domain objects to these form objects for every page (and still possibly have to pass in the domain object if I need some values I’d be using read-only for that page).

I’m sure I’m overlooking / over-complicating something here.

Update An interesting find after playing around because of what @Charlino said. If I used the strongly typed html helpers to make the inputs (Html.TextBoxFor()) it will remember the values even if the view is typed to the domain object. If I use the generic ones (Html.TextBox()) or raw HTML it doesn’t seem to.

  • 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-18T08:45:55+00:00Added an answer on May 18, 2026 at 8:45 am

    Having a ViewModel object for each and every view is what I end up doing.

    It is a bit more up-front work, as I have to define the ViewModel and mapping, but that code is so simple and straightforward it takes only seconds to write.

    Often, when I need a form, I make a separate Form object, and have the ViewModel contain it.

    public class MyViewModel 
    {
        public string SomeNonFormDisplayValue { get; set; }
        public bool AnotherDisplayOnlyValue { get; set; }
        public IEnumerable<Tuple<int, string>> SelectionListItems { get; set; }
    
        public MyViewsForm Form { get; set; }
    }
    
    
    public class MyViewsForm
    {
        public string EditableProperty { get; set; }
        public int SelectionListItemId { get; set; }
    }
    

    I type my View to the ViewModel, but I make the Post Action Method take just the form.

    public class MyController
    {
        [HttpGet]
        public ActionResult Edit() { ... }
    
        [HttpPost]
        public ActionResult Edit(MyViewsForm form) { ... }
    }
    

    I also make query methods to retrieve the ViewModel, one that populates the form and another that does not – for when I return the POST’d form with errors.

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

Sidebar

Related Questions

I often see a pattern used in circumstances where we have look-up code that
I created an API wrapper called Chargify.NET and I'm starting to see a pattern
so after a few weeks, i have got my head around asp.net mvc and
I have a Regex object created with the new Regex(string pattern) constructor, is there
The following code illustrates a pattern I sometimes see, whereby an object is transformed
I have the following two classes and I am starting to see a pattern
I have an MVC-based site, which is using a Repository/Service pattern for data access.
im looking at the MVC pattern, and I can see in one example on
I am testing a small stub of Matcher and Pattern class...see the following small
In classes that implement INotifyPropertyChanged I often see this pattern : public string FirstName

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.