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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:35:56+00:00 2026-05-10T21:35:56+00:00

I have an ASP.NET MVC project with a form. In the Action method that

  • 0

I have an ASP.NET MVC project with a form. In the Action method that handles the POST verb I have a custom IModelBinder implementation that is binding the form data to my model instance. If there are errors I am using bindingContext.ModelState.SetAttemptedValue() and bindingContext.ModelState.AddModelError() to persist the submitted value and error message to the ModelState.

This works great and I can see the expected behavior occurring on my input controls that are rendered with Html.TextBox() (which calls through to Html.InputHelper()). When I use Html.CheckBox() (which also calls through to Html.InputHelper()) the state of my CheckBox is NOT output to th <input /> tag.

It seems to me like the Html.InputHelper() method is not using the AttemptedValue from the ModelState for input fields of type CheckBox.

Here is the code from ASP.NET MVC Html.InputHelper() method.

Why is it that the CheckBox attemptedValue is not output to the input tag. Is there something I am missing here or do I need to manually handle this case by checking the ModelState and setting the tag attribute myself?

Update 11/09
Here is the call to HtmlHelpers that I am using to output the CheckBox:

<%= Html.CheckBox('IsDerived') %> 

And here is the call that I am using to register the Attempted Value:

string isDerivedRequestValue = !string.IsNullOrEmpty(bindingContext.HttpContext.Request['IsDerived']) ? bindingContext.HttpContext.Request.Form.GetValues('IsDerived') [0] : null; bindingContext.ModelState.SetAttemptedValue('IsDerived', isDerivedRequestValue); 
  • 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. 2026-05-10T21:35:57+00:00Added an answer on May 10, 2026 at 9:35 pm

    I’m not sure if this is the best way to solve the problem or not, but since the Html.InputHelper() method is not checking the AttemptedValue for CheckBox controls I added the following to my controller which embeds the proper value from the ModelState into ViewData and seems to do the trick quite well.

    ViewData['IsDerived'] = ViewData.ModelState.ContainsKey('IsDerived')                            ? bool.Parse(ViewData.ModelState['IsDerived'].AttemptedValue)                            : false; 

    Make sure you are not explicitly setting the isChecked parameter value when you call Html.CheckBox() as that will override any value stored in ViewData.

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

Sidebar

Ask A Question

Stats

  • Questions 77k
  • Answers 77k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer The view structure is based on the controllers, not the… May 11, 2026 at 3:28 pm
  • added an answer Your question has a logical error...if Dispose() is called within… May 11, 2026 at 3:28 pm
  • added an answer This should, technically, work, provided you change Class2 to include… May 11, 2026 at 3:28 pm

Related Questions

So I'm embarking on an ASP.NET MVC project and while the experience has been
I been waiting for sometime now to bring my Asp.net Preview 4 project up
I have been working my way through Scott Guthrie's excellent post on ASP.NET MVC
I'm trying to go through the NerdDinner example chapter from the ASP.Net MVC 1.0

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.