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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:30:03+00:00 2026-06-05T11:30:03+00:00

CheckBoxFor(t => t.boolValue, new { disabled=disabled }) method to render a checkbox, in disabled

  • 0

CheckBoxFor(t => t.boolValue, new { disabled=”disabled” }) method to render a checkbox, in disabled mode.

The method renders a hidden field as well.

My question is why does this hidden field has a false value for disabled check box?
I believe the purpose of the hidden field is to have some extra behavior over the default check box behavior

Is there a way to override default MVC functionality so that the value of this hidden field
is based on the state of the checkbox even in disabled mode?

  • 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-05T11:30:05+00:00Added an answer on June 5, 2026 at 11:30 am

    The hidden field is used to bind the checkbox value to a boolean property. The thing is that if a checkbox is not checked, nothing is sent to the server, so ASP.NET MVC uses this hidden field to send false and bind to the corresponding boolean field. You cannot modify this behavior other than writing a custom helper.

    This being said, instead of using disabled="disabled" use readonly="readonly" on the checkbox. This way you will keep the same desired behavior that the user cannot modify its value but in addition to that its value will be sent to the server when the form is submitted:

    @Html.CheckBoxFor(x => x.Something, new { @readonly = "readonly" })
    

    UPDATE:

    As pointed out in the comments section the readonly attribute doesn’t work with Google Chrome. Another possibility is to use yet another hidden field and disable the checkbox:

    @Html.HiddenFor(x => x.Something)
    @Html.CheckBoxFor(x => x.Something, new { disabled = "disabled" })
    

    UPDATE 2:

    Here’s a full testcase with the additional hidden field.

    Model:

    public class MyViewModel
    {
        public bool Foo { get; set; }
    }
    

    Controller:

    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View(new MyViewModel { Foo = true });
        }
    
        [HttpPost]
        public ActionResult Index(MyViewModel model)
        {
            return Content(model.Foo.ToString());
        }
    }
    

    View:

    @model MyViewModel
    
    @using (Html.BeginForm())
    {
        @Html.HiddenFor(x => x.Foo)
        @Html.CheckBoxFor(x => x.Foo, new { disabled = "disabled" })
        <button type="submit">OK</button>
    }
    

    When the form is submitted the value of the Foo property is true. I have tested with all major browsers (Chrome, FF, IE).

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

Sidebar

Related Questions

CheckBoxFor renders a hidden field with the same name ( and for good reason
@this.Html.CheckBoxFor(m => m.MyModel.MyBoolProperty, new { @class=myCheckBox, extraAttr=23521}) With razor, I'm unable to specify values
I've got an editor template which renders out a checkbox: @Html.CheckBoxFor(model => model.Follow) Which
I have referred this question to learn how to post the checkbox selected values
I'm trying to create a dynamic CheckBoxFor where some items are disabled. This is
Here is how i created my Checkbox: @Html.CheckBoxFor(model => model.IsFinal, new { @readonly =
I don't why the Html.CheckBoxFor(x => x.IsChecked) helper was implemented. Why does it force
can I use it like this in View? <%= Html.CheckBoxFor(user => user.Role, Administrator)%> and
So I have an extension method for the Html.CheckBoxFor() method that enables the user
@Html.CheckboxFor(m -> m.List[0].Value) // Value is bool property generates something like this: <input id=List_0__Value

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.