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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:25:57+00:00 2026-06-13T08:25:57+00:00

I have a Model property which the controller sets to 1 but in my

  • 0

I have a Model property which the controller sets to 1 but in my view I see it as 0 and 1 depending on how I access it.

View snippet (these lines are absolutely consecutive too!)

@Html.DisplayFor(model => model.resumeStage)    
@Html.HiddenFor(model => model.resumeStage)
@Html.EditorFor(model => model.resumeStage)

Rendered HTML (I moved the value= at the front of the tag for readability)

1
<input value="0" data-val="true" data-val-number="The field resumeStage must be a number." data-val-required="The resumeStage field is required." id="resumeStage" name="resumeStage" type="hidden" />
<input value="0" class="text-box single-line" id="resumeStage" name="resumeStage" type="number" />

Shouldn’t the value always be 1? I seem to lose the state of that property when I present it inside a text box! The views-controllers are strong bound by the model class which is defined as

public class CreateUserModel
{
    [Required]
    public int resumeStage { get; set; } // <== problem

    public LocalProfile newLocalUser { get; set; }
    public ExtProfile newExtUser { get; set; }

    public CreateUserModel()
    {
        resumeStage = 0;
        newLocalUser = new LocalProfile();
        newExtUser = new ExtProfile();
        preFillWithTestData();
    }

    private void preFillWithTestData()
    {
        // prefill the newLocalUser
        // and newExtUser classes with dummy data
    }
}

The controller method receiving the form POST (where I flip the int from 0=>1) is :

[HttpPost]
public ActionResult UserRegistration(CreateUserModel newUser)
{
    try
    {
        //stage 0, setup local account
        if (newUser.resumeStage <= 0)
        {
            // do stuff
            newUser.resumeStage = 1;
        }

        // stage 1, setup external account
        if (newUser.resumeStage <= 1)
        {
            // test an exception
            Exception ex = new Exception("TEST: External service provider offline");
            throw ex;
            newUser.resumeStage = 2;
        }

        return RedirectToAction("Index");
    }
    catch (Exception ex)
    {
        return View(newUser); // newUser.resumeStage is 1 here but 
                              // view will disagree
    }
}

The controller method creating and presenting the form is:

public ActionResult UserRegistration()
{
    // Constructor prefills with test data, nothing more to do
    CreateUserModel newUser = new CreateUserModel();

    return View(newUser);
}

Question: Does anyone know why I cannot seem to have resumeStage shown as 1 inside the HTML rendered Textbox?

  • 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-13T08:25:58+00:00Added an answer on June 13, 2026 at 8:25 am

    You should add ModelState.Remove("resumeStage"); or add a call to ModelState.Clear();

    catch (Exception ex)
    {
        ModelState.Remove("resumeStage");
        return View(newUser); // newUser.resumeStage is 1 here but 
                              // view will disagree
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a view model with a property Fields which is an ObservableCollection<FieldVM> .
I have a property in my view model which returns a constant under some
I have a controller which is depended on a model property. I wrote a
I have a model which defines a property with either markdown or html content.
I have a view with 1 dropdown generated from Model property and 3 additional
How do I bind a view model property to the ListBox.SelectedItem property? I have
I have a view model with an Email address property and a Confirm Email
I have a model which has a boolean property and some other properties that
Say I have a list of model objects and a controller object which is
I have strong-type view, I want to create link that refers to Model, which

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.