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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:34:49+00:00 2026-06-02T14:34:49+00:00

Based on Darin’s answer to my question Ho to display multiple checkbox selection based

  • 0

Based on Darin’s answer to my question Ho to display multiple checkbox selection based on user's selection from dropdown?
I am displaying multiple checkboxes based on dropdown selection.

Now, once the user post the form (with multiple inputs) that i have on my page, i collect all the data using FormCollection. And the problem i have is how can i pull those selected checkbox values from formcollection? The number of checkbox will change on different selection from the drop-down, so i think requesting each checkbox value will not work.

Can anyone help me with this problem.

The flow is as shown below:

Properties in Model

public class Subcategory
{
    public string Name { get; set; }
    public int ID { get; set; }
    public bool Flag { get; set; }
}

Displaying PartialView in actual view where other form inputs are there:

 <div id="checkboxlist">
      @if (Model.SubCategories != null)
      {
           @Html.Partial("SubCategories", Model.SubCategories)
      }
 </div>    

PartialView SubCategories.cshtml

@model IEnumerable<MyProject.Entities.Subcategory>
@{
// we change the HTML field prefix so that input elements
// such as checkboxes have correct names in order to be able
// to POST the values back 
ViewData.TemplateInfo.HtmlFieldPrefix = "checkboxlist";
}
<span>subcategory</span>
<div id="subcategories" style="margin-left: 130px;margin-top: -20px;" data-role="fieldcontain">
   <fieldset data-role="controlgroup">
      @Html.EditorForModel()
   </fieldset>
</div> 

EditorTemplates Subcategory.cshtml

@model MyProject.Entities.Subcategory
<div class="editor-label">
   @Html.CheckBoxFor(c => c.Flag, new { type = "checkbox" })
   <label for="@Model.ID">@Model.Name</label>
   @Html.HiddenFor(c => c.Flag)
   @Html.HiddenFor(c => c.ID)
   @Html.HiddenFor(c => c.Name)
</div>

jquery to display checkboxes based on dropdown selection:

 $('#Category').change(function () {
    var subcategoriesUrl = $(this).data('subcategoriesurl');
    var categoryId = $(this).val();
    $('#checkboxlist').load(subcategoriesUrl, { category: categoryId });
 });
  • 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-02T14:34:50+00:00Added an answer on June 2, 2026 at 2:34 pm

    Don’t use FormCollection. That’s weakly typed. Use view models. Like this:

    [HttpPost]
    public ActionResult Foo(MyViewModel model)
    {
        // model.BusinessSubCategories should contain a list of Subcategory
        // where for each element you could use the Flag property to see if
        // it was selected or not
        ...
    }
    

    Also notice that you have an inconsistency between the field prefix that you are using in your partial:

    ViewData.TemplateInfo.HtmlFieldPrefix = "checkboxlist";
    

    and the view model collection property: Model.BusinessSubCategories. So make sure you fix the prefix to use the correct property name if you want the default model binder to be able to populate this property when you post back.

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

Sidebar

Related Questions

Based on the answer from axtavt, this is almost certainly a naming problem between
Based on the great answer at multi-step registration process issues in asp.net mvc (splitted
I'm trying to stream an audio file from a server protected by session-based authentication,
I am calling a web service from a C# forms based app. ServReturnType obj
Problem: jQuery DataTables server-side processing using ASP.NET WebForms. Solution: Darin Dimitrov answered the question
Based on the redirect below, How could I get it to redirect from 2007-2010?
Based on the PlayN Getting Started wiki page I created a skeleton project (called
Based on http://tutorialzine.com/2011/06/beautiful-portfolio-html5-jquery/ tutorial I am trying to implement a sort function to my
Based on Java Servlet Specification Version 3.0 : In the Web application deployment descriptor,
Based on my current understandings, when you have an UpdatePanel control there is no

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.