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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:42:48+00:00 2026-05-25T20:42:48+00:00

I have created a strongly typed MVC3 Razor view using the scaffolding code. The

  • 0

I have created a strongly typed MVC3 Razor view using the scaffolding code.

The model is a POCO with a base type of PersistentEntity which defines a property called Created, Updated and Id.

Id is an int, Created and Updated are DateTime.

I am using Html.HiddenFor to create the hidden field on the view.

@Html.HiddenFor(model => model.Id)
@Html.HiddenFor(model => model.Created)
@Html.HiddenFor(model => model.Updated)

On the page, the hidden input is being rendered properly, with the Id being set in the value.

<input data-val="true" data-val-number="The field Id must be a number." data-val-required="The Id field is required." id="Id" name="Id" type="hidden" value="12">

However when the page is submitted to the controller [HttpPost]Edit(Model model) the Id property is always 0. Created and Updated are correctly populated with the values from the View.

enter image description here

This should be 12 in the case of the example in this post. What is going wrong?


I am aware that I can change the method signature to [HttpPost]Edit(int personID, Person model) as the personID is in the get string, however why does the model not get populated with the hidden field?


Update

The problem was that the setter on PersistentEntity was protected, ASP could not set the property, and swallowed it. Changing this to public has solved the problem.

public abstract class PersistentEntity
{
    public virtual int Id { get; protected set; }
    public virtual DateTime Created { get; set; }
    public virtual DateTime Updated { get; set; }
}
  • 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-25T20:42:49+00:00Added an answer on May 25, 2026 at 8:42 pm
    public virtual int Id { get; protected set; }
    

    protected set; <!-- That’s your problem. You need a public setter if you want the default model binder to be able to assign the value.

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

Sidebar

Related Questions

I have a strongly typed MVC3 Razor view in which I want to display
I have a strongly typed view that is using a viewmodel I created. I
I have a strongly typed view of type ProductListingViewModel which in turn contains a
I have a strongly typed view, Edit, with a model named OrderModel. In this
I have a strongly typed DataTable created with the VS2005/VS2008 DataSet designer. The table
For strongly-typed & type-safe solution, I have to do the following step. Create some
I have created a strongly typed dataset in the VS 2005 Dataset Designer. There
In .NET you can create strongly-typed configuration sections using build-in base classes that do
I have a strongly-typed Partial View that takes a ProductImage and when it is
I have a strongly typed Person view, that I want to render a partial

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.