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

  • Home
  • SEARCH
  • 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 8757467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:18:31+00:00 2026-06-13T14:18:31+00:00

Background I have a bool in a view model class. I have an if

  • 0

Background

I have a bool in a view model class. I have an if statement checking to see if the bool is true or false. If false I set the value to true and call a view. In the view I have button that when clicked updates and calls the view again. My problem is that the bool keeps being set to false when the view is loaded. I don’t know why this is happening. Is there a way to stop the bool from being changed?

Attempts

I’m aware MVC is stateless.

The view I’ve been given to work with is a .aspx view with the “value” attribute of the input tag already being used. So I’m unable to update the value of the Submit button.

<input type="submit" class="button" value="bvCalc" />

Question

In whatever way, I’m looking to persist the state of the bool. I don’t know how to do this and I’m unsure as to whether or not the best thing to do at this point would be to

  1. use a hidden field in the view
  2. build an HTML Helper Extension that will update the bool from true to false
  3. return the modified value with the model information being sent back to the controller so I can evaluate the data in the if statement.
  • 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-13T14:18:33+00:00Added an answer on June 13, 2026 at 2:18 pm

    The way values get from a view to controller is via ModelBinding. If you are not familiar with how this works you might like to Google it to get a better understanding.

    As a quick example, lets say the action method in your controller that you want to pass the bool to looks like this:

    public ActionResult MyAction(MyViewModel model)
    {
      //.. do something here.
    }
    

    and your ViewModel looks like this:

    public class MyViewModel
    {  
       public bool MyBool { get; set; }
       // ...more properties...
    }
    

    As long as your view has some kind of field (e.g. text box, checkbox, hidden field) with a name that exactly matches the property name (in this case ‘MyBool’) and a value that will convert to the property (in this example the string ‘True’ can map to to the boolean true value) – ModelBinding will be able to populate model.MyBool with true in your controller action.

    If you use the built-in helper methods, you don’t need to worry about getting the correct name/value in your field element – MVC will do this for you

    e.g. @Html.HiddenFor(model => model.MyBool) will render HTML something like

    <input type="hidden" id="MyBool" name="MyBool" value="True" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background: I have an MVC based polaroid object. The model keeps the photo's metadata,
Background I have an array of objects (Users) defined and set as follows: //
I have the starter point of my application this window (white background): - (BOOL)application:(UIApplication
I have a strongly typed View class that all my UserControls derive from. It
I have created a simple application which has a red background and a button
I have UILocalNotification the has two buttons a cancel and view button when the
I have Listbox which is bound to my view model. This view model has
I have an AVAudioPlayer that needs to continue in the background. Audio is set
I have the following code in my viewWillAppear: - (void) viewWillAppear:(BOOL)animated{ self.view.backgroundColor = [UIColor
i have background music when the view is open then the music is start

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.