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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:08:25+00:00 2026-05-23T08:08:25+00:00

I have this code and I can’t understand why it works this way I

  • 0

I have this code and I can’t understand why it works this way

I have a model and view which is arbitrary and a very simple (but weird) controller

Here is my controller:

public partial class RouteController : Controller
{
    [HttpGet]
    public virtual ActionResult Create()
    {
        Create create = new Create();
        return View("Create", create);
    }

    [HttpPost]
    public virtual ActionResult Create(Create route)
    {
        return Create();
    }
}

The first create method loads the view as normal. When the view posts back it runs the 2nd action which runs the first (as expected). The wierd part is the view is (re-)loaded with my previously entered data with errors (if any). I dont understand this because my model is empty. I was expecting it to post back with the same form as if it was loaded for the first time but with errors possibly.

Please explain.

  • 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-23T08:08:26+00:00Added an answer on May 23, 2026 at 8:08 am

    That’s the normal behavior of HTML helpers and it is by design. They first look at values contained in the ModelState and after that in the actual model. If you intend to modify some values on the model in a POST action you need to remove them from modelstate first:

    For example:

    [HttpPost]
    public virtual ActionResult Create(Create route)
    {
        ModelState.Remove("SomeProperty");
        route.SomeProperty = "some new value";
        return View(route);
    }
    

    If you intend to completely modify everything as in your example you could clear the modelstate entirely:

    [HttpPost]
    public virtual ActionResult Create(Create route)
    {
        ModelState.Clear();
        return Create();
    }
    

    Another possibility is to write your own TextBoxFor, HiddenFor, CheckBoxFor, … helpers that will use the value in the model and not the one in the model state. Or yet another (non-recommended) possibility:

    <input type="text" name="SomeProperty" value="@Model.SomeProperty" />
    

    Of course in this case client validation among other things provided by the standard helpers won’t work.

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

Sidebar

Related Questions

I have this code but I just can't understand it. using System; using System.Collections.Generic;
i have this code, but i can't understand why var_dump($jobs[0][0]) return Some Director ,
I have this code, but it won't compile and i can't understand what is
I have this simple code but I can't figure for the life of me
I have this code to update users data, but I can't write the for
I encountered something that I can't understand. I have this code: cout << f1
i have this code that can do fast search on database. it works excellent
i have this code it can go to if(array_key_exists('p',$_POST)) but can't go to if(isset($_POST['p'][$i])
i have this code but i can't see the action when i click on
I have this code to draw a triangular canvas. But I can't manage to

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.