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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:49:35+00:00 2026-06-04T07:49:35+00:00

I have a simple MVC controller and view and model (I removed all other

  • 0

I have a simple MVC controller and view and model (I removed all other codes to figure out the problem)
Model is a simple one property class:

public class SiteFileUploadModel
{
    [Required]
    public int ActivePage { get; set; }
}

View is also very simple:

@model Models.SiteFileUploadModel
@{
      ViewBag.Title = "Index";
 }
 <h2>Index</h2>
 @if (Model != null)
 {
      using (this.Html.BeginForm("Index", "SiteFileUpload"))
      {
           @Html.Hidden("ActivePage",Model.ActivePage)
           @Model.ActivePage
           switch (Model.ActivePage)
           {
                case 1:
                    <p>Page 1</p>
                    break;
                case 2:
                    <p>Page 2</p>
                    break;
           }
           <button type="submit" name="actionButtons">Previous</button>
           <button type="submit" name="actionButtons">Next</button>
      }
  }

The controller has only one method:

public class SiteFileUploadController : Controller
{
    //
    // GET: /FileUpload/SiteFileUpload/
    [HttpGet]
    public ActionResult Index()
    {
        var model = new SiteFileUploadModel();
        model.ActivePage = 1;
        return View(model);
    }

    [HttpPost]
    public ActionResult Index(SiteFileUploadModel model, string actionButtons)
    {
        if (actionButtons == "Next")
        {
            model.ActivePage++;

        }
        if (actionButtons == "Previous")
        {
            model.ActivePage--;
        }

        return View(model);
    }

}

When I am running it and press next, I can see that model.activePage became 2 and it also shows on output (it shows 2 and page 2), but the hidden value is still 1. In fact the hidden value is always 1 and it doesn’t follow the real value of ActivePage. I also tested it with generating hidden field using HiddenFor(m=>m.ActivePage) with the same effect! What is the problem?

  • 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-04T07:49:37+00:00Added an answer on June 4, 2026 at 7:49 am

    See this answer.

    In brief, you need to clear the ModelState before redisplaying the view, as the Html Helper will use the model state rather than the Model for its data.

    Add the following statement to your controller action:

    ModelState.Clear();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple ASP.NET MVC 3 site, from my Controller out of the
I need a simple MVC framework, without jQuery extensions, hibernate, loggers, etc.. Only Model-View-Controller
Have a simple Spring MVC portlet, and from one of portal pages I have
I need to explain to a not-very-technical manager the MVC (model-view-controller) concept and ran
I'm writing my first application with Zendframework. My question is about the Model–View–Controller (MVC)
I have a very simple MVC app at this point: Controller: public class HomeController
In my Asp.net MVC app, I have two methods on a controller, one for
I have a simple MVC form with the following elements: <%= Html.TextBox(FechaInicio) %> Which
I have a simple MVC 4 (Beta) Application and just observed something that I
I have a very simple MVC site that is returning a 404 not found

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.