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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:07:51+00:00 2026-05-31T12:07:51+00:00

I’m new to MVC 3 and I have the following views: Index: @using (Html.BeginForm())

  • 0

I’m new to MVC 3 and I have the following views:

Index:

@using (Html.BeginForm())
{
    @Html.Hidden("id", "1")
    <input type="submit" value="Submit" />
}

Main:

@using (Html.BeginForm())
{
    @Html.Hidden("id", "2")
    <input type="submit" value="Save" />
}

And the following Controller:

public ActionResult Index()
{
    ViewBag.Message = "Welcome!";
    return View();
}
[HttpPost]
public ActionResult Index(string id)
{
    if ("1".Equals(id))
    {
        return View("Main");
    }
    else("2".Equals(id))
    {
        return View();
    }
}

My expectation would be that the Main view would render the hidden input with a value of “2”. However, upon reaching the Main page, and inspecting the source, the value is still being set to “1”. Any idea what I’m doing wrong here?

  • 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-31T12:07:53+00:00Added an answer on May 31, 2026 at 12:07 pm

    That depends on the URL you are using. If you are entering ..../Index, then it will go to the Index view, but if you are going to .../Index/1 then it will go to the Main view and render your two (which is kind of odd because a 1 goes to 2 :))

    Also, you will only hit the Index(string id) method on a POST, so that might also be your problem. a typical URL request comes across as a GET

    If that does not help, then you might need to provide more details (what URL you are attempting to hit, and how you are trying to get there)

    UPDATE AFTER TRYING THIS MYSELF

    I see what you are saying. The reason for the hidden field being set to 1 is because the ModelState plugs it in for you. As far as I can tell, this should NOT happen since you are explicitly setting the value. However, it appears that if there is a matching state item, it will use that instead. You can test this by changing from using id to anything else in your Main’s hidden input name.

    Here is the documentation. In the remarks, it does state that this is meant more for model binding, but I would have thought that the value inserted would override anything else.

    FINAL UPDATE

    It turns out that this actually has already been brought up to the appropriate person, and it is by design. They SHOULD change the documentation to make this more explicit, though. Here is the SO question that answers this

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I have thousands of HTML files to process using Groovy/Java and I need to
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have a jquery bug and I've been looking for hours now, I can't
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.