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 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 65k
  • Answers 65k
  • 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 Python's string format method can take a format spec. >>>… May 11, 2026 at 11:18 am
  • added an answer I've had some success with this code: <Style TargetType='ListBox' x:Key='ListStyle'… May 11, 2026 at 11:18 am
  • added an answer Yes, it would return the view that was actually touched… May 11, 2026 at 11:18 am

Related Questions

I have an ASP.NET MVC project with a form. In the Action method that
I have an ASP.NET MVC project and I have a single action that accepts
I'm building an ASP.Net MVC website. Rather than have everything in one project, I've
I have an ASP.NET MVC-application which I want deployable on both IIS6 and IIS7
I have an asp.net mvc application with a route similar to: routes.MapRoute(Blog, {controller}/{action}/{year}/{month}/{day}/{friendlyName}, new
I have an ASP.NET MVC (Beta 1) website that I'm using themes with. When
I have an ASP.NET MVC application, when a user clicks on the submit button
I have an ASP.Net MVC Ajax.BeginForm that submits and updates my page properly when
I have an asp.net mvc app running on a local iis website that is
I have an ASP.NET MVC view which contains checkboxes for user-defined categories. <td><% foreach

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.