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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:22:33+00:00 2026-06-05T18:22:33+00:00

The default strongly-typed Edit page in ASP.NET MVC 3 generally exposes all fields for

  • 0

The default strongly-typed Edit page in ASP.NET MVC 3 generally exposes all fields for the Entity. While this is often workable, some fields are a security risk. For example a simplified magazine subscription entity might look like:

public void Subscription() {
  public int Id { get; set; }
  public string Name { get; set; }
  public string Address { get; set; }
  public string City { get; set; }
  public string State { get; set; }
  public string Zip { get; set; }
  public DateTime SubscribedThru { get; set; }
}

If I provide an Edit page to let users change their own address, for example, it’s a security risk to include the SubscribedThru field because a knowledgeable and malicious user could give themselves a free 10-year subscription by faking the date (even if I use @Html.HiddenFor(model => model.SubscribedThru). So I am not including that field in any way on the Edit page html (via razor).

I thought the answer might be to prevent binding attempts on SubscribedThru on the Edit method in the controller using something like:

[HttpPost]
public ActionResult Edit([Bind(Exclude="SubscribedThru")] Subscription subscription) {
  if (ModelState.IsValid) {
    db.Entry(subscription).State = EntityState.Modified;
    db.SaveChanges();
    return RedirectToAction("Index");
    }
  }
  return View(subscription);
}

When I get to the SaveChanges(); line, it throws the error The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value. I believe that the SubscribedThru date (properly?) doesn’t exist, and the empty value is less than SQL Server can handle. What surprises me is that it’s even trying to update that field when I have Binding excluded for it.

So far my best solution seems to be to create a custom ViewModel that omits the SubscribedThru date, but that seems a lot of duplication of fields, validation, etc.; if possible I’d like to just make the one field SubscribedThru safe from user editing.

I can’t say I fully understand the UpdateModel and TryUpdateModel methods and wonder if that’s a direction to head? I played with them and EF throws errors for having duplicate objects (same key) which is perplexing.

Also, I’m not clear if the subscription data is preserved from the initial load in public ActionResult Edit(int id) in the controller all the way to the final [HttpPost]
public ActionResult Edit(Subscription subscription)...
method, or does the line db.Entry(subscription).State = EntityState.Modified; try and set all the data (I thought it was just setting a flag indicating “edited-so-EF-should-save-this”).

I’m a long-time .NET developer, just jumping in to my first ASP.NET MVC project, so I’m probably overlooking something painfully obvious. Thanks for any help!

  • 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-05T18:22:34+00:00Added an answer on June 5, 2026 at 6:22 pm

    So far my best solution seems to be to create a custom ViewModel that omits the SubscribedThru date, but that seems a lot of duplication of fields, validation, etc.;

    That is exactly what you should do to keep things neat & tidy. AutoMapper eases the ViewModel variation headache.

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

Sidebar

Related Questions

I am using asp.net mvc 2.0(default binding model) and I have this problem. I
Given that strongly typed ActionLink is not viable ( Strongly Typed ActionLink In Asp.Net
By default the new project template for ASP.NET MVC 3 adds the following to
By default the listbox in ASP.NET has a 3D border effect. I need to
Does ASP.NET MVC offer any simple way to get model binding to work when
I've got an MVC 3 form in a strongly typed view where one of
I'm new to MVC, but I've been all over this, read all the documentation
I'm trying to use an Html.RenderAction in a strongly typed nature from the MVC
I'm trying to build a global menu into my ASP.NET MVC site.master, and I
i'm trying to make my site master page ( views/shared/site.master ) strongly typed. eg.

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.