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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:26:36+00:00 2026-05-25T10:26:36+00:00

I had in my classes some fields that represents true or false, but it

  • 0

I had in my classes some fields that represents true or false, but it has string values “T” or “F”.

How to bind the checkbox to these fields?

  • 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-25T10:26:37+00:00Added an answer on May 25, 2026 at 10:26 am

    You can do this in ASP.Net MVC Razor

    <input type="checkbox" name="someName" value="@Model.SomeValue" 
    @(Model.IsChecked == "T" ? "checked='checked'" : "") />
    

    However, this may not be what you are looking for, since you would have to do some manual work on the server to figure out values that had been “unchecked”.

    By default only your checked values will get sent to the server.

    UPDATE:

    The Html.CheckBox and Html.CheckBoxFor helper methods both emit hidden fields in order to make sure everything binds correctly back to your model. You can imitate this behavior pretty easily.

    First you need to emit a hidden field that will be bound to your model on the server.

    @Html.HiddenFor(model => model.StringBool, new { id = "_stringBool" })
    

    Next you create a plain jane checkbox and set the initial state to reflect your model.

    <input type="checkbox" id="myCheckBox" @(Model.StringBool == "T" ? "checked='checked'" : "") />
    

    This checkbox’s only purpose is to proxy values to and from the hidden field so your model will automatically get bound on the server. This can be achieved with some simple jQuery.

    $("#myCheckBox").click(function () {
       var isChecked = $(this).is(":checked");
    
       $("#_stringBool").val(isChecked ? "T" : "F");
    });
    

    Now checking and unchecking the box will set the value of your bound hidden field accordingly. When you post to the server your values will be preserved via model binding.

    Some things to note

    This does not take into account validation. It is very easy to change the value of the hidden field so make sure you properly validate on the server side!

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

Sidebar

Related Questions

I had a discussion with some colleagues mentioning that there are not too many
I've had several classes - university level - on Java. However, what these classes
I want to change the background color of the DIV depending on some true/false
I had a painful experience with the Analysis of Algorithms classes back in college
We recently had a code review . One of my classes was used so
I'm currently working on a project were I had to wrap the C++ classes
In Ruby I have often written a number of small classes, and had a
Had an interesting discussion with some colleagues about the best scheduling strategies for realtime
I have a form containing a list of input fields that the user populates
I'm trying to use some Java-classes with Clojure. I've tried it with Scala with

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.