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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:52:51+00:00 2026-06-12T17:52:51+00:00

The problem I’m having right now it’s that ASP.NET MVC validates the request object,

  • 0

The problem I’m having right now it’s that ASP.NET MVC validates the request object, user in this case

public ActionResult Edit(User user)

What I want to do is that if the user’s password is left blank, do not update the password, just use the old password, but if it’s set, update it.

The problem is that the framework complains that user does not has a password, even if I update the user object, it complains

public ActionResult Edit(User user)
{
    user.Password = "Something";

    // more code...
}

Apparently it does the validation on the request object, is there a way I can skip the validation in this case, or at least delay it until I finished modifying the user object?

This is the full method code

[HttpPost]
public ActionResult Edit(User user)
{    
    if (string.IsNullOrEmpty(user.Password))
    {
        var oldUser = db.Users.Single(u => u.Id == user.Id);
        user.Password = oldUser.Password;
    }

    try
    {
        db.SaveChanges();
        return RedirectToAction("Index");
    }
    catch
    {
        return View(user);
    }
}
  • 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-12T17:52:52+00:00Added an answer on June 12, 2026 at 5:52 pm

    The model state will still be invalid even after you set the password to something. After you do that try clear the model state using ModelState.Clear(); Or modify the ModelState accordingly i.e clear the error state only for password property ModelState.Remove("Password");

    [HttpPost]
    public ActionResult Edit(User user)
    {    
        if (string.IsNullOrEmpty(user.Password))
        {
            var oldUser = db.Users.Single(u => u.Id == user.Id);
            user.Password = oldUser.Password;
            ModelState.Clear(); // or change the state accordingly (ModelState.Remove("Password");)
        }
    .......
    }
    

    From your posts it looks like you are ware of the [Required] attribute on the password field. I suggest you force javascript validation and let the user know that they cannot update the password to be blank. Or if you are updating User information in a form that doesn’t include password create a new viewmodel or temp model that does not have the password field and the model is specific to that form. Post to this model and bind to this model. Then update the actual user model by using the data from the temp user model. This will be better practice to follow.

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

Sidebar

Related Questions

Problem: I have a table that prints out vertical but I would like it
Problem occured when i tried to display xml data that has been taken by
Problem Statement:- I have four shell script that I want to execute only when
Problem with displaying news from database! Screenshoot: Database(table) Articals: ID, Title, Content, User Very
problem defenition i have one model called 'user.php' i have some validation rules on
Problem with my approach is that image, text or line drawn, lags by maybe
Problem is like this: Suppose there are records in dataTable with FruitType as A
Problem Description: Multi-player Game that works over the some kind of network, in game
Problem is like this: I have two winapi application's. There is only one way
Problem background: I have a Qt/QML Symbian application targeting Qt 4.7.4, that requires a

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.