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 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

Related Questions

Is there a simple way to use a typedef based on an if condition?
Is there a way to use simple sql queries on ASP MVC without using
Is there a simple way to make an HTML page automatically adjust for mobile
Is there a way to use the existing WPF BooleanToVisibilityConverter converter but have False
Is there a way to set flyway to use an existing java.sql.Connection as DataSource,
is there a simple way of creating a button collection from the existing buttons
Is there a simple way to insert the current time (like TIME: [2012-07-02 Mon
Is there a simple way to serialize a single-level structure as a string for
Is there a simple way, possibly with open-source command line tools in Linux, to
Is there a simple way in Symfony 1.4 to know whether a submitted form

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.