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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:49:34+00:00 2026-05-25T18:49:34+00:00

In an Edit action in ASP.NET MVC, certain fields can be hidden from user

  • 0

In an Edit action in ASP.NET MVC, certain fields can be hidden from user with HiddenFieldFor. However this doesn’t protect the fields (such as ID, data creation date) from being edited.

For example, a model Student has fields Id, Name and Birthday. I like to allow users to update the Name, but not Id nor Birthday.

For an Edit action like this

public ActionResult Edit(Student student)
{
    if (ModelState.IsValid)
    {
        db.Entry(student).State = EntityState.Modified;
        db.SaveChanges();
        return RedirectToAction("Index");
    }
    return View(student);
}

How can I prevent Id and Birthday from being edited? 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-05-25T18:49:35+00:00Added an answer on May 25, 2026 at 6:49 pm

    You should use a view model which contains only the properties that you want to be edited:

    public class EditStudentViewModel
    {
        public string Name { get; set; }
    }
    

    and then:

    public ActionResult Edit(StudentViewModel student)
    {
        ...
    }
    

    Another technique which I don’t recommend is to exclude certain properties from binding:

    public ActionResult Edit([Bind(Exclude = "Id,Birthday")]Student student)
    {
        ...
    }
    

    or include:

    public ActionResult Edit([Bind(Include = "Name")]Student student)
    {
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On ASP.NET MVC 3, I created a Action Filter for white space removal from
After reading ASP.NET MVC 2 in Action and watching Jimmy Bogard's presentation from MvcConf
This is ASP.NET MVC 2. Basically, I call an action in a controller with
I would like to edit the ASP.NET MVC templates for Visual Studio so that
I have ASP.NET MVC application with action which should process posted XML data. At
I am using asp.net MVC. I have edit page url like {controller}/Edit/2 so on
I have a simple ASP.NET MVC 3 site, from my Controller out of the
The recommended way to make an edit page for ASP.NET MVC is to have
When I try to use Html.Action in ASP.NET MVC 3 for a controller in
I have an Action method in an ASP.NET MVC Controller class that handles form

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.