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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T18:52:28+00:00 2026-06-03T18:52:28+00:00

I have a partialview [_SearchProduct] within the main view, let’s say [product] view. The

  • 0

I have a partialview [_SearchProduct] within the main view, let’s say [product] view. The Partialview has a number of checkboxes segregated into different sections like search by company,search by product etc. with one [search] button.

A User can select multiple checkboxes. When user clicks [search] button I need to pass ids of all selected checkbox to controller action and re-render the page again considering the user’s selection . Please guide me how to pass selected checkbox ids to my controller action.

My partial view is something like below:

<fieldset>
<legend>By Company</legend>
<table  style="border-style: none;">
   <tr>
        @{
            int i = 0;
            foreach (var item in Model.CompanyName)
            {

                i = i + 1;
            <td style="border-style: none;text-decoration:none;" >
                @Html.CheckBox("chkCompany",new {id="chkCompany_" + Model.CompanyId.Tostring()}) @Model.CompanyName
            </td>
                if (i == 5)
                {
                    @:</tr><tr>
                    i = 0;
                }

            }
        }
    </tr>
</table>
</fieldset>

<fieldset>
<legend>By Product</legend>
<table  style="border-style: none;">
    <tr>
        @{
             i = 0;
            foreach (var item in Model.Product)
            {
                i = i + 1;
            <td style="border-style: none;text-decoration:none;" >
                @Html.CheckBox("chkProduct",new {id="chkProduct_" + Model.CompanyId.Tostring()}) @Model.ProductName
            </td>
                if (i == 10)
                {
                    @:</tr><tr>
                    i = 0;
                }

            }
        }
    </tr>
</table>
</fieldset>
  • checkboxes are dynamic
  • Checkbox id represent the primarykey of respective table based on which i do filtering.

Please guide me>>

  • 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-03T18:52:40+00:00Added an answer on June 3, 2026 at 6:52 pm

    So it sounds like you have a structure containing names (of companies/products), and ids.

    I would create a View Model structure that looked like

    public class PartialViewModel //Make sure this is included in your main view model
    {
        public List<ObjectsToInclude> Companies { get; set; }
        public List<ObjectsToInclude> Products { get; set; }
    }
    
    public class ObjectsToInclude //Give this a better name
    {
        public string Name { get; set; }
        public string Id { get; set; }
        public bool Include { get; set; }
    }
    

    Then in order to bind them you could do

    for (int i =0; i<Model.Companies.Count(); i++)
    {
       <td style="border-style: none;text-decoration:none;" >
                @Html.HiddenFor(m => m.Companies[i].Id)
                @Html.CheckBoxFor(m => m.Companies[i].Include) @Model.Companies[i].Name
       </td>
       if (i == 5)
       {
           @:</tr><tr>
           i = 0;
       }
    
    }
    

    Then provided your post takes a parameter of PartialViewModel (or some MainViewModel where that contains an instance of PartialViewModel), you’ll have lists of companies and products binded. You can loop through the list, and take the respective ids of anything checked to be included.

    Edit: If you wanted a single comma separated array to be posted, it would be possible by by creating an onclick event for your checkboxes, and then setting a value of a hidden input every time a checkbox is clicked. But then your code would only work with JavaScript enabled. If you need a comma separated string, you can create it server side with the view model I suggested.

    string companyIds = String.Join(",", model.Companies
        .Where(company => company.Include)
        .Select(company => company.Id));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a partial view that has a number of Div's, each are set
I have a main view and the URL for this view has a Action/Controller/Area
I have a partial view that uses a Telerik MVC Grid, and it has
I have a PartialView strongly typed to a view model <%@ Control Language=C# Inherits=System.Web.Mvc.ViewUserControl<VATRateManager_MVC.Models.ViewModels.RateControlEditViewModel>
I have a simple PartialView setup in my MVC3 Project using the Razor View
I have a controller calling a view. In the view there is a PartialView
Context Let`s say i have: In layout Site.Master: <div class=leftColumn> <asp:ContentPlaceHolder ID=MainContent runat=server />
I have a PartialView which I need to create a button on, and once
I have a partial view that I want to basically take care of itself
I have a partial view that is shared between two controllers and I'm trying

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.