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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:02:29+00:00 2026-06-17T15:02:29+00:00

I have a simple edit form for a user model but when I post

  • 0

I have a simple edit form for a user model but when I post back, none of the hidden input values are being applied to model and I’m not sure why this is happening.

My Razor:

@model CMS.Core.Models.UserProfile

@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)

    <fieldset class="normalForm">
        <legend>User Profile</legend>

        @Html.HiddenFor(model => model.UserId)

        <div class="formRow">
            <div class="editor-label">
                @Html.LabelFor(model => model.EmailAddress)
            </div>
            <div class="editor-field">
                @Html.TextBoxFor(model => model.EmailAddress, new { @class = "textbox" })
                @Html.ValidationMessageFor(model => model.EmailAddress)
            </div>
        </div>

        <div class="formRow">
            <div class="editor-label">
                @Html.LabelFor(model => model.FirstName)
            </div>
            <div class="editor-field">
                @Html.TextBoxFor(model => model.FirstName, new { @class = "textbox" })
                @Html.ValidationMessageFor(model => model.FirstName)
            </div>
        </div>

        <div class="buttonRow"><input type="submit" value="Save" class="button" /></div>
    </fieldset>
}

My Controller:

    [HttpPost]
    public ActionResult Edit(UserProfile user)
    {
        if (ModelState.IsValid)
        {
            user.Save();
            return RedirectToAction("Index");
        }
        return View(user);
    }

UserProfile class:

[Table("UserProfile")]
public class UserProfile
{
    [Key]
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
    public int UserId { get; private set; }


    [Required(ErrorMessage = "Please enter an email address")]
    [StringLength(350)]
    [DataType(DataType.EmailAddress)]
    [Display(Name = "Email Address")]
    public string EmailAddress { get; set; }


    [StringLength(100)]
    [DataType(DataType.Text)]
    [Display(Name = "First Name")]
    public string FirstName { get; set; }
}

If I try user.UserId it returns zero (as it is an int) but if I try Request["UserId"] it returns the correct value so the value is being posted correctly – just not added into the UserProfile model. Does anyone know why this is happening or what I can do to solve it

Thanks

  • 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-17T15:02:31+00:00Added an answer on June 17, 2026 at 3:02 pm

    The DefaultModelBinder only able to bind public properties.

    Change your property setter to public and it should work fine:

    [Key]
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
    public int UserId { get; set; }
    

    If you can’t do that you will need create a custom model binder which deals with private setters.

    However as a better approach instead of using your UserProfile directly. Create a UserProfileViewModel where your UserId is public and use that in your View and Controller action. In this case you need to map between your UserProfile and the UserProfileViewModel but there are good tools exists for that task like AutoMapper.

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

Sidebar

Related Questions

I have a simple form where a user can add, edit, and delete people
I have a simple HTML Form <form id=uploadForm method=post action=/cgi-bin/test.cgi enctype=multipart/form-data> <input type=submit name=add_something
I have a VERY simple windows form that the user uses to manage Stores.
I have this page :8000/edit/6/ that show a form to update an exciting model
I have simple registration form. Once all information entered, user click submit button and
I have a form to edit employee information. If the user wishes to enter
I have a post model with a datetime field called published_at. On my form
I have a simple in-line edit in my grid, and I want to commit
Edit (updated question) I have a simple C program: // it is not important
This seems like such a simple question. I have several Edit boxes on my

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.