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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:58:21+00:00 2026-05-22T19:58:21+00:00

In my ASP.NET MVC 3 app I have a page where, after its form

  • 0

In my ASP.NET MVC 3 app I have a page where, after its form is submitted I need to change a value from the form. If I do it in the ViewModel it has no effect, I have to do it use ModelState["Field"].Value.

The thing is that I actually have a lot of work I have to do on the ViewModel when the pages loads AND after the POST. So I have a method which receives the ViewModel and do all that work. But, as I said, after the POST, modifying the ViewModel object is useless. Why is that? The method on the controller is returning View(viewModel);. Shouldn’t the view use the ViewModel values?

I’d like to understand why is useless to modify the ViewModel and also know if there is some method in the ModelState which “refresh” the fields values throw a ViewModel object.

Here is my controllers code:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(MyViewModel viewModel)
{
    try
    {
        if (ModelState.IsValid)
            //Do stuff and redirect
    }
    catch(Exception ex)
    {
        //Log and add error to the ModelState
    }

    someMethodWhichDoesALotOfThingsInTheViewModel(viewModel);
    return View(viewModel);
}

I think the rest of the code is unnecessary, if anyone think it would help let me know!

Update

I don’t want to lose any errors, not even those of the fields changed in the ViewModel. A good example would be a captcha, if the users makes any error in the form (only with the captcha field or only with any other fields and not with the captcha) I want to show him all his errors and also update the captcha. It makes no sense to render the form with the old captcha value inserted so I want to blank that field.

Update 2

I’ve opted to put @Value = Model.PropertyInViewModel in the HTML Attributes of each Html.TextBoxFor. But I’d prefer to avoid that nasty work so if someone comes out with any better solution please let me know.

  • 1 1 Answer
  • 2 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-22T19:58:22+00:00Added an answer on May 22, 2026 at 7:58 pm

    All I could came out with is to add @Value = Model.PropertyInViewModel to each Html.TextBoxFor that is going to be modified in the ViewModel.

    Another way, as @Darin Dimitrov said, would be to make my own helpers.

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

Sidebar

Related Questions

I have an asp.net mvc 2 app. I need to display the same page
I have an ASP.NET MVC app and I want to add to each page
In my ASP.NET MVC app, I have a fairly complex edit page which combines
I have a shared page in my ASP.NET MVC app that can be accessed
I have built an ASP.NET MVC app some time ago, and after a few
I have an ASP.NET MVC web app and have a function that I need
Background I have a page on my ASP.NET MVC web app for users to
I have an interesting situation where I need to deploy an ASP.NET MVC app
Using Unity in an ASP.Net MVC 2 app I have various dependencies on Controllers
Im trying to develop my first ASP.NET MVC web app and have run into

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.