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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:57:03+00:00 2026-06-14T05:57:03+00:00

I am attempting to create an MVC action method that allows users to progressively

  • 0

I am attempting to create an MVC action method that allows users to progressively review a sequence of database records. Each time a user posts an update, it is submitted to the database and a new record is retrieved and rendered, for review.

However, my MVC view appears to be combining data from both the posted view model and the new view model that is created as a result of the database query. When the view simply renders property values from the view model, it correctly uses those from the view model instance that was passed to it, but when it binds an HTML form control to a view model property, it uses values from the posted view model. This means that a single view is able to display two different values for a single property on a single view model instance:

enter image description here

Here’s a very simplified version of the action method …

public ActionResult Index(MyViewModel model)
{
    if (ModelState.IsValid)
    {
        // Write the posted model data to the repository
        // ...

        // Retrieve a new entity for the user to work on
        var alternate = new MyViewModel { Name = "New Name" };

        return View(alternate);
    }

    return View(model);
}

… and the view model …

public class MyViewModel
{
    [Required]
    public string Name { get; set; }
}

… and the view that was used to create the above image …

@model Mvc4TestApplication.ViewModels.MyViewModel

Name: @Model.Name
@using (Html.BeginForm())
{
    @Html.LabelFor(model => model.Name)
    @Html.TextBoxFor(model => model.Name)
    <input type="submit" value="Submit"/>
}

It seems that I have misunderstood the way MVC views discover their model data. Is there some alternate syntax that I should use to explicitly tell the view to bind its form controls to the view model that was passed to it?

Thanks,

Tim.

  • 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-14T05:57:04+00:00Added an answer on June 14, 2026 at 5:57 am

    Try clearing the ModelState. The htmlhelpers are using the ModelState to get values.

    ModelState.Clear();
    

    Before you return View()

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

Sidebar

Related Questions

I'm attempting to implement a Create action method for an ASP.NET MVC web application.
I am attempting to create a strongly typed view with a MVC View User
I am attempting to create a report, utilizing a matrix, that only displays columns
I'm attempting to create a single Controller class to handle all foreseeable surveys that
I'm attempting to create themeing system for my asp.net mvc application. I was able
I am attempting to get a MVC 3 generated 'Create' page to have all
In my ASP.NET MVC 2 web application, I allow users to create custom input
I'm attempting to create a custom calendar control that inherits from ASP.Net's built in
I am attempting to create new membership users in an Ektron CMS400.NET-based website by
I'm making the transition to MVC 3 and was attempting to create a friendly

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.