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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:42:44+00:00 2026-06-01T10:42:44+00:00

I have a model like the following one: public class TestModel{ public IList<Field> Fields

  • 0

I have a model like the following one:

public class TestModel{
    public IList<Field> Fields {get; set;}
}

public class Field{
    public String Key {get; set;}
    public String Value {get; set;}
}

How would I have to make the corresponding view form, to get the Model correctly binded after the post request? The user should be able to select the various Fields with checkboxes and the Model should contain the selected ones.
In the Action method below, the Model’s members are null.

public ActionResult XY(TestModel 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-01T10:42:45+00:00Added an answer on June 1, 2026 at 10:42 am

    i have added to your model a Selected property

    i have added an EditorTemplate to display a single Field

    what will happen now when you submit, all the items will be send you can then filter all the item that have a property of Selected=true

    The Model

    public class TestModel
    {
        public IList<Field> Fields { get; set; }
    }
    
    public class Field
    {
        public String Key { get; set; }
        public String Value { get; set; }
        public bool Selected { get; set; }
    }
    

    The Controller [TestController.cs]

    public ActionResult Index()
    {
        var testModel = new TestModel();
        testModel.Fields = new List<Field>
                                {
                                    new Field { Key = "Choice 1" , Selected = true , Value = "1"},
                                    new Field { Key = "Choice 2" , Selected = false , Value = "2"},
                                    new Field { Key = "Choice 3" , Selected = false , Value = "3"}
                                };
        return View(testModel);
    }
    
    [HttpPost]
    public ActionResult XY(TestModel model)
    {
        var selectedFields = model.Fields.Where(f => f.Selected);
    
        /** Do some logic **/
    
        return View();
    }
    

    The View [/Views/Test/Index.cshtml]

    @model MvcApplication2.Models.TestModel
    
    @using(@Html.BeginForm("XY","Test"))
    {
        @Html.EditorFor(m => m.Fields)
        <input type="submit" value="submit"/>
    }
    

    The Editor Template [/Views/Test/EditorTemplates/Field.cshtml]

    @model MvcApplication2.Models.Field
    <label>
        @Html.CheckBoxFor(m =>m.Selected)
        @Model.Key 
    </label>
    @Html.HiddenFor(m =>m.Value)
    @Html.HiddenFor(m =>m.Key)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class: public class Car { public string Model {get;set;} public string
I have the following code: modelBuilder.Entity<User>().HasMany(x => x.Items).WithRequired(); The model looks like public class
Consider the following model: public class BandProfileModel { public BandModel Band { get; set;
I have the following entity model: public class Project { [Key] public int ProjectID
I'm using MVC3 and I have a model like this: public class Foo {
I have a simple model like this one: class Artist(models.Model): surname = models.CharField(max_length=200) name
Let's say I have the following two classes: package example.model; public class Model {
I have the following view model: public class MyViewModel { public bool SingleFamily {
I have the following model in MVC: public class IndexViewModel { public SubViewModel SubViewModel
I have the following model : class Model extends BaseModel { public function save($conn

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.