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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:55:17+00:00 2026-06-16T03:55:17+00:00

Here is my scenario. Created two Models that have a common property name public

  • 0

Here is my scenario.

  1. Created two Models that have a common property name

    public class SimpleModel1
    {
    // Some Properties
    
    public string Property1 { get; set; }
    
    }
    
    public class SimpleModel2
    {
    // Some Properties
    
    public string Property1 { get; set; } // Same name as Property1 in SimpleModel1
    
    }
    
  2. Used SimpleModel1 in an Action (for e.g. Index) that returns a view that looks like this

    @model MvcApplication2.Models.SimpleModel1
    
    @{
    ViewBag.Title = "Home Page";
    }
    
    @using (Html.BeginForm("Test", "Home", FormMethod.Post))
    {
      <label>Enter something here</label>
       @Html.TextBoxFor(m => m.Property1)
       <button type="submit">Submit</button>
    }
    
  3. Submitted the value to a Test action that takes SimpleModel1 as parameter, does some work, and returns a view that takes in SimpleModel2

    public ActionResult Test(SimpleModel1 model)
    {
        SimpleModel2 newModel = new SimpleModel2();
    
        // Do Something
    
        newModel.Property1 = "Something different than model's Property1";
    
        return View(newModel);
    }
    
  4. The Test.cshtml (view returned by Test action) is as below:

    @model MvcApplication2.Models.SimpleModel2
    
    @{
        ViewBag.Title = "Test";
    }
    
    <h2>Test</h2>
    
     @* Model Propery without using HTML extension*@
     @Model.Property1
    
     @* Model property using HTML extension (Incorrect) *@
    
     @Html.TextBoxFor(m => m.Property1)
     @Html.HiddenFor(m => m.Property1)
     @Html.TextAreaFor(m => m.Property1)
    
      @* Correct Value *@
     <input value="@Model.Property1" />
    

What I expect is that all the values of Property1 would be “Something different than model’s Property1” as set in Test Action. But it turns out that the ones that use the Html extension (Html.TextBoxFor, Html.HiddenFor etc) have the Property1 value that was posted to Test Action. For example, if I post “What a surprise” ( the Property1 of SimpleModel1) to Test Action, the value of Property1 of SimpleModel2 is also “What a surprise” no matter what I set it to.

I have no idea what is going on. Looks like a bug to me. Does anyone have any idea?

  • 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-16T03:55:18+00:00Added an answer on June 16, 2026 at 3:55 am

    You will see this behavior when doing a POST because posted data is persisted in ModelState. The value for Property1 will be whatever the value was posted for this property.
    In order to see your new value you need to include this line of code in your ActionResult Test:

    ModelState.Clear();
    

    As a general rule just remember to include this line in case you are posting data, modifying it and trying to see modified data on the returned view.

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

Sidebar

Related Questions

Here's the scenario: You have two seperate websites that exist in different environments (I.E.
The scenario Suppose I have the following two model classes: public class ProductColor {
Here is my scenario: I have two MySQL tables: Categories (columns: id, category) Items
Here's the scenario: I have a public repo A . Bob forks A ,
Here's the scenario. I have a legacy system with two parts, Part A and
I have the following scenario: at runtime two parent entities are created. Each of
Here is the scenario: I have successfully bound two objects from a native ObjC
Here's my scenario: I have a simple stored procedure that removes a specific set
Here's our scenario: We've created a sharepoint 2007 calendar on our intranet site We
Here is my scenario. User fills out this large page which is dynamically created

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.