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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:46:36+00:00 2026-06-10T02:46:36+00:00

I currently have an object Tag defined as follows: public class Tag { public

  • 0

I currently have an object Tag defined as follows:

public class Tag
{
    public string Name { get; set; }
}

Now, this is a collection property of a Model which I’m defining as:

public class MyModel
{
    public string Name { get; set; }
    public IList<Tag> Tags { get; set; }
}

In my view I have the following code:

@using (Html.BeginForm())
{
    <div>
        @Html.LabelFor(m => m.Name)
        @Html.TextBoxFor(m => m.Name)
    </div>

    <div>
        <!--
        Here I'd like a collection of checkbox inputs, where the selected names
        get passed back to my controller via the IList<Tag> collection
        -->
    </div>

    <input type="submit" value="Submit" />
}

How do I return the selected items on my checkbox group (specified in comments) via the IList collection of my model?

  • 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-10T02:46:37+00:00Added an answer on June 10, 2026 at 2:46 am

    Use Editor Templates

    For having the Checkbox, Add another Proeprty to your Tag classs to specify whether it is selected or not.

    public class Tag
    {
        public string Name { get; set; }
        public bool IsSelected { set; get; }
    }
    

    Now from your GET Action, you can set a List of Tags in your Model’s Tags Property and sent it to the View.

    public ActionResult AddTag()
    {
        var vm = new MyModel();
    
        //The below code is hardcoded for demo. you mat replace with DB data.
        vm.Tags.Add(new Tag { Name = "Test1" });
        vm.Tags.Add(new Tag { Name = "Test2" });
    
        return View(vm);
    }
    

    Now Let’s create an Editor Template, Go to The View/YourControllerName and Create a Folder called EditorTemaplates and Create a new View there with the same name as of the Property type ( Tag.cshtml).

    enter image description here

    Add this content to the new editor template now.

    @model Tag
    <p>
      <b>@Model.Name</b>   :
      @Html.CheckBoxFor(x => x.IsSelected) <br />
      @Html.HiddenFor(x=>x.Name)
    </p>
    

    Now in your Main View, Call your Editor template using the EditorFor Html Helper method.

    @model MyModel
    <h2>AddTag</h2>
    @using (Html.BeginForm())
    {
        <div>
            @Html.LabelFor(m => m.Name)
            @Html.TextBoxFor(m => m.Name)
        </div>    
        <div>  
          @Html.EditorFor(m=>m.Tags)         
        </div>    
        <input type="submit" value="Submit" />
    }
    

    Now when You Post the Form, Your Model will have the Tags Collection where the Selected Checkboxes will be having a True value for the IsSelected Property.

     [HttpPost]
    public ActionResult AddTag(MyModel model)
    {
       if(ModelState.IsValid)
       {
          //Check for model.Tags collection and Each items IsSelected property value.
          //Save and Redirect(PRG pattern)
       }
       return View(model);
    }
    

    Like this

    enter image description here

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

Sidebar

Related Questions

Currently I have an object which I receive from a server, this contains two
I currently have a Javascript function that uses a string to reference an object
I currently have a function: public static Attribute GetAttribute(MemberInfo Member, Type AttributeType) { Object[]
Currently I have a simple knockoutJS object, with a few observables. But this object
Currently I have this code var App = Ember.Application.create(); App.user = Ember.Object.create({ people: customers
Here is what I have currently, I'm doing this: current_account.send(object).search(params[:search]).user_id_equals_any(users).visibility_is_any(visibilities) but thats not very
I currently have 3 tables: News ID | Title Tag ID | Name TaggedContent
Currently I have a DataModel object which contains my linq to sql classes(a dmbl
I have a tableView showing an NSMutableArray of an object and I am currently
I have been working on keeping things object oriented for my project. Currently, I'm

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.