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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:21:52+00:00 2026-06-05T10:21:52+00:00

Given a class public class Person { // Some general properties public List<Hobby> Hobbies

  • 0

Given a class

public class Person
{
    // Some general properties

    public List<Hobby> Hobbies { get; set; }
}

public class Hobby
{
    // Some properties e.g. Name, etc.
}

static List<Hobby> AllHobbies { get; }

Is it possible to create a view that allows the user to select his hobbies using model binding?

It would certainly be possible in the view to loop through AllHobbies and render an <input type="checkbox" /> for each, then wire up the selected values by hand in the postback controller. It seems that this should be doable with model binding, but I don’t see how.

  • 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-05T10:21:53+00:00Added an answer on June 5, 2026 at 10:21 am

    Sure, I would recommend you using editor templates.

    Let’s suppose that a hobby has a name and a boolean field indicating whether it was selected by the user:

    public class Hobby
    {
        public string Name { get; set; }
        public bool Selected { get; set; }
    }
    

    then a controller to feed the model into the view and process the form submission:

    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            var person = new Person
            {
                Hobbies = new[]
                {
                    new Hobby { Name = "hobby 1" },
                    new Hobby { Name = "hobby 2", Selected = true },
                    new Hobby { Name = "hobby 3" },
                }.ToList()
            };
            return View(person);
        }
    
        [HttpPost]
        public ActionResult Index(Person person)
        {
            var selectedHobbies = person
                .Hobbies
                .Where(x => x.Selected).Select(x => x.Name);
            string message = string.Join(",", selectedHobbies);
            return Content("Thank you for selecting: " + message);
        }
    }
    

    then a view containing the form allowing the user to select hobbies:

    @model Person
    
    @using (Html.BeginForm()) 
    {
        <h2>Hobbies</h2>
        @Html.EditorFor(x => x.Hobbies)
        <button type="submit">OK</button>
    }
    

    and a corresponding editor template which will automatically be rendered for each element of the Hobbies collection (~/Views/Home/EditorTemplates/Hobby.cshtml -> notice that the name and location of the template is important):

    @model Hobby
    
    <div>
        @Html.LabelFor(x => x.Selected, Model.Name)
        @Html.HiddenFor(x => x.Name)
        @Html.CheckBoxFor(x => x.Selected)
    </div>
    

    For more advanced editing scenarios I would recommend you going through the Steven Sanderson’s blog post on this topic.

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

Sidebar

Related Questions

Given the classes: public class Person { public string Name { get; set; }
Given the model: public abstract class Person { public int Id {get;set;} } public
Given a class such as: class Person { private: char *name; public: Person() {
Given this object class Contact { public IEnumerable<Person> People { get; } public string
Say i have the following: public class Person{ public int ID {get; set;} public
Given a simple class: public class Person { public string FirstName; public string LastName;
In c#, Given the following code: public class Person { public int PersonID {
Given two methods on the same class in Java : public void doSomething( Person
Given: class A { public void m(List l) { ... } } Let's say
Given a string: Person.Address.Postcode I want to be able to get/set this postcode property

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.