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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:58:49+00:00 2026-05-24T23:58:49+00:00

I have a following view model and it will be used by a search

  • 0

I have a following view model and it will be used by a search control that I’m working on.

public class SearchViewModel
{
    public SearchViewModel()
    {
        SearchLocation = new SearchLocationViewModel();
        SearchCategories = new SearchCategoriesViewModel();
    }

   public SearchLocationViewModel SearchLocation { get; set; }
   public SearchCategoriesViewModel SearchCategories { get; set; }
}

Now, SearchCategoriesViewModel has the following structure:

public class SearchCategoriesViewModel
{
    [Display(Name = "Categories")]
    public IList<SearchCategoryViewModel> Categories { get; set; }

    public SearchCategoriesViewModel()
    {
        Categories = new List<SearchCategoryViewModel>();
    }
}

And, finally, search category view model has the following structure:

    public class SearchCategoryViewModel
    {
        [Required]
        [Display(Name="Id")]
        public int Id { get; set; }

        [Display(Name="Name")]
        public String Name { get; set; }

        public bool IsSelected { get; set; }
    }

When I submit a search request, the SearchLocationViewModel comes through with submitted parameters, however, SearchCategoriesViewModel comes through empty (not null).

Below is an editor template for my SearchCategoryViewModel:

@model MyDLL.WebUI.Models.SearchCategoriesViewModel

@foreach (var c in Model.Categories)
{
    @Html.Label(c.Name);
    @Html.CheckBox(c.Name,c.IsSelected);
}

I use the following view to generate the search controls:

@using (Html.BeginForm()) {
    @Html.ValidationSummary(true) 

    <div id="search">
        @Html.EditorFor(m => m.SearchCategories, "SearchCategory")            
        @Html.EditorFor(m => m.SearchLocation, "SearchLocation")            
    </div>

    <p>
        <input type="submit" value="Create" />
    </p>    
}   

I end up with the following markup:

   <h2>Search</h2>

<form action="/Settings/Search" method="post">        


<label for="SearchCategories_Professional">Professional</label>
<input id="SearchCategories_Professional" name="SearchCategories.Professional" type="checkbox" value="true" />
<input name="SearchCategories.Professional" type="hidden" value="false" />

<label for="SearchCategories_Associate">Associate</label><input id="SearchCategories_Associate" name="SearchCategories.Associate" type="checkbox" value="true" />
<input name="SearchCategories.Associate" type="hidden" value="false" />            

        <p>
            <input type="submit" value="Create" />
        </p> 

</form>

I suspect that the parameters are not coming through because generated markup is wrong. Did any of you try generating partial views from complex objects? I don’t want to pass IEnumerable, I would rather have it encapsulated in a seperate class so that I can extend/remove it in the future if needed.

Thank you

  • 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-24T23:58:49+00:00Added an answer on May 24, 2026 at 11:58 pm

    Because you have a static list, you can quickly hack your way to creating markup which will be bound correctly:

    @model MyDLL.WebUI.Models.SearchCategoriesViewModel
    @{
        var i = 0;
    }
    @foreach (var c in Model.Categories) 
    {
        @Html.Hidden("Categories[" + i.ToString() + "].Id", c.Id);
        @Html.Hidden("Categories[" + i.ToString() + "].Name", c.Name);
        @Html.Label(c.Name);
        @Html.CheckBox("Categories[" + i.ToString() + "].IsSelected",c.IsSelected);
    } 
    

    This is a quick and ugly solution. However, I would suggest that you reconsider how you are generating the markup in your partial view.

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

Sidebar

Related Questions

I have the following model, view and controller. Model public class Person { public
I have the following code in a view: <div class=wrap_select> @Html.DropDownList(dateRange, new SelectList(Model.DateRange, Value,Text),
I have the following view model: Public Class MyViewModel Public Property SelectedIDs As List(Of
I have the following view: @model MyModel1 @{ ViewBag.Title = Index; Layout = ~/Views/Shared/_Layout.cshtml;
In my view I have the following code: @using (Html.BeginForm()) { @Html.TextBox(Date2, Model.Date2) <br/>
in a partial view I have the following: <%Html.RenderAction(MVC.User.GetComments(Model.UserGroupName)); %> can I render a
I have the following ViewModel, which is the base class of other ViewModels that
I have the following ViewModel public class RecommendationModel { public List<CheckBoxItem> CheckBoxList { get;
I have the following structure: class FeatureType(models.Model): type = models.CharField(max_length=20) def __unicode__(self): return self.type
I have an iPad application that can be used in all four view modes

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.