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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:32:30+00:00 2026-05-11T09:32:30+00:00

Is there a simple way to use the existing Html Helpers to generate a

  • 0

Is there a simple way to use the existing Html Helpers to generate a list of checkboxes with explicit values (as was possible in Beta)?

Example in Beta (possibly with MVC Contrib):

.CheckBox('Field', 6, new { value = 6}) would output:

<input id='Field1' type='checkbox' value='6' name='Field' /> <input id='Field2' type='hidden' value='6' name='Field' /> 

yet in RC2 I get:

<input id='Field1' type='checkbox' value='6' name='Field' /> <input type='hidden' value='false' name='Field' /> 

NB: I use a custom helper extension that generates unique HTML ids and sets the checked HTML attribute when appropriate

Besides using raw HTML and not using Html Helpers is there a way of setting checkboxes with explicit values? Looking at the Codeplex source code for RC2 there doesn’t appear to be an easy way as .InputHelper() is marked private so you can’t use it to help.

NB: There’s more than one checkbox in the page to allow multiple selection, so the false value is of no use, as I need the values from the hidden field to know which items were ticked and which weren’t (as non-checked checkbox values aren’t posted – only the hidden fields are).

  • 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-11T09:32:31+00:00Added an answer on May 11, 2026 at 9:32 am

    As a workaround I’ve come up with the following based loosely on the RC2 sourcecode’s InputHelper method, but adapted it to allow multiple values:

     private static string CheckBoxWithValue(this HtmlHelper htmlHelper, string name, object value, bool isChecked, bool setId, IDictionary htmlAttributes)         {             const InputType inputType = InputType.CheckBox;             if (String.IsNullOrEmpty(name))             {                 throw new ArgumentException('null or empty error', 'name');             }              var tagBuilder = new TagBuilder('input');             tagBuilder.MergeAttributes(htmlAttributes);             tagBuilder.MergeAttribute('type', HtmlHelper.GetInputTypeString(inputType));             tagBuilder.MergeAttribute('name', name, true);             string valueParameter = Convert.ToString(value, CultureInfo.CurrentCulture);              if (isChecked)             {                 tagBuilder.MergeAttribute('checked', 'checked');             }             tagBuilder.MergeAttribute('value', valueParameter, true);             if (setId) tagBuilder.GenerateId(name);              // If there are any errors for a named field, we add the css attribute.             ModelState modelState;             if (htmlHelper.ViewData.ModelState.TryGetValue(name, out modelState))             {                 if (modelState.Errors.Count > 0)                 {                     tagBuilder.AddCssClass(HtmlHelper.ValidationInputCssClassName);                 }             }             var inputItemBuilder = new StringBuilder();             inputItemBuilder.Append(tagBuilder.ToString(TagRenderMode.SelfClosing));              var hiddenInput = new TagBuilder('input');             hiddenInput.MergeAttributes(htmlAttributes);              hiddenInput.MergeAttribute('type', HtmlHelper.GetInputTypeString(InputType.Hidden));             hiddenInput.MergeAttribute('name', name);             if (setId)             {                 hiddenInput.GenerateId(name);             }             hiddenInput.MergeAttribute('value', valueParameter);              inputItemBuilder.Append(hiddenInput.ToString(TagRenderMode.SelfClosing));             return inputItemBuilder.ToString();          } 

    This relies on .ToString() your evaluate the object’s value, but is adequate for my scenario where i’m using integers to represent options with the lookup done in the backend database. Note the setId boolean seems to just replace dots in the Html name with underscore characters. When using multiple checkboxes in HTML the IDs should be unique so I simply pass in the unique Id via htmlAttributes collection instead.

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

Sidebar

Ask A Question

Stats

  • Questions 75k
  • Answers 75k
  • 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 Use the Interlocked operations, here's some sample code: LONGLONG AtomicRead(LONGLONG*… May 11, 2026 at 2:53 pm
  • added an answer I found the issue :) Unless something has changed in… May 11, 2026 at 2:53 pm
  • added an answer I'd put it the other way around: you might be… May 11, 2026 at 2:53 pm

Related Questions

I am using Python to read in data in a user-unfriendly format and transform
I need to implement a simple and efficient XSS Filter in C++ for CppCMS
I need to automatically generate a PDF file from an exisiting (X)HTML-document. The input
I'm looking for a consistent way to structure my use of formatting strings throughout

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.