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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:45:52+00:00 2026-05-29T23:45:52+00:00

In my update actions I am doing this: [HttpPost] public ActionResult Update() { if(Request.Form[…])

  • 0

In my update actions I am doing this:

[HttpPost]
public ActionResult Update()
{

  if(Request.Form["..."])
  {

  }
  ..

}

So I am grabbing the ID of the entity, then loading it, then updating the properties based on the posted form values.

I’m using MVC2.

How should I be doing this as I read about model state but not sure how to start?

I want to refactor to make this right.

Update

My viewmodel looks like:

public class SomeViewModel
{
   public User User {get; set;}
}
  • 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-29T23:45:53+00:00Added an answer on May 29, 2026 at 11:45 pm

    You should define a view model containing all the necessary information that the view will send:

    public class MyViewModel
    {
        public int Foo { get; set; }
    
        [Required]
        public string Bar { get; set; }
    
        [Required]
        public DateTime? Baz { get; set; }
    }
    

    and then have your controller action take this view model as parameter:

    [HttpPost]
    public ActionResult Update(MyViewModel model)
    {
        if (!ModelState.IsValid) 
        {
            // validation failed (the user left the Bar field empty) =>
            // we redisplay the view so that he can fix the errors
            return View(model);
        }
    
        // at this stage we know that the model is valid =>
        // we could do some processing. The model.Foo and model.Bar
        // properties will contain the values entered by the user in the 
        // corresponding form fields so that you don't need to fetch them
        // manually from the Request. The default model binder will take
        // care of this
    
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update: Check out this follow-up question: Gem Update on Windows - is it broken?
I'm having a windows form. In this form I've datagrid control which has few
I have a JPA domain entity that I'm updating from user input. Depending on
Using asp.net mvc, a user updates his profile. This is how my update action
I'm using InnoDB. When delete and update actions occur on a particular table, I
If I render the update action from inside the create action, is there a
I have an Edit action and an Edit view to allow users to update
def update @album = Album.find(params[:id]) if @album.update_attributes(params[:album]) redirect_to(:action=>'list') else render(:action=>'edit') end end A Rails
Update: Solved, with code I got it working, see my answer below for the
Update: giving a much more thorough example. The first two solutions offered were right

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.