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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:11:10+00:00 2026-06-11T20:11:10+00:00

I have below class : public class ControllerSecurityModel { public string ControlleName { get;

  • 0

I have below class :

public class ControllerSecurityModel
{
    public string ControlleName { get; set; }
    public string DisplayName { get; set; }
    public List<ActionSecurityModel> actions { get; set; }
}
public class ActionSecurityModel
{
    public string ActionName { get; set; }
    public string DisplayName { get; set; }
    public bool IsChecked { get; set; }
}

and a model :

public class PageRoleModel
{
    public List<ControllerSecurityModel> AllPages { get; set; }

    public List<ControllerSecurityModel> SelectedPage { get; set; }
}

I want to have checkbox for each “ActionSecurityModel” , I write below view :

<% using (Html.BeginForm())
   {%>
<% foreach (var cont in Model.AllPages)
   {%>
<fieldset>
    <legend>
        <%= cont.DisplayName  %></legend>
    <% foreach (var act in cont.actions)
       {%>
    <%: Html.CheckBoxFor(x => act.IsChecked) %>
    <%: Html.Label(act.DisplayName) %>
    <% } %>
</fieldset>
<% } %>
<input type="submit" value="save"/>
<% } %>

and this my controller action :

    public ActionResult SetRole()
    {
        PageRoleModel model = new PageRoleModel();

        return View(model);
    }

    [HttpPost]
    public ActionResult SetRole(PageRoleModel model)
    {
        return View(model);
    }

but when I submit form the model is null?
How can I submit checkboxes and save them?

  • 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-11T20:11:11+00:00Added an answer on June 11, 2026 at 8:11 pm

    Like this:

    <% using (Html.BeginForm()) { %>
        <% for (var i = 0; i < Model.AllPages.Count; i++) { %>
        <fieldset>
            <legend>
                <%= Model.AllPages[i].DisplayName %>
            </legend>
            <% for (var j = 0; j < Model.AllPages[i].actions.Count; j++ ) { %>
                <%= Html.CheckBoxFor(x => x.AllPages[i].actions[j].IsChecked) %>
                <%= Html.Label(Model.AllPages[i].actions[j].DisplayName) %>
            }
        </fieldset>
        <% } %>
        <input type="submit" value="save"/>
    <% } %>
    

    To understand why my solution works and your not, please read about the expected wire format that the default model binder uses for collections. Then look at the generated names of the form input fields by browsing the generated HTML source code – you will quickly see a fundamental difference in the name attribute of the checkbox.

    Also don’t expect to get your entire model bound in the POST action. You only have a single input field inside your form – a checkbox. So that’s the only value that’s gonna be sent to the server and bound to the model. If you needed the other values as well you could include them as hidden fields:

    <!-- in the outer loop: -->
    <% =Html.HiddenFor(x => x.AllPages[i].DisplayName) %>
    ...
    <!-- and then in the inner loop -->
    <%= Html.HiddenFor(x => x.AllPages[i].actions[j].ActionName) %>
    <%= Html.HiddenFor(x => x.AllPages[i].actions[j].DisplayName) %>
    ... and so on ...
    

    Also I would very strongly recommend you using editor templates instead of writing those loops in your views. They automatically will take care of generating proper names for your input fields so that you don’t have to worry about. I have gazillions of answers on this topic. Just Google my name and add editor templates asp.net mvc to your search and you should get many results.

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

Sidebar

Related Questions

i have class like below class Person { public string Name{get;set;} public string Surname{get;set;}
I have an entity similar to the below: public class Entity { public List<DateItem>
I have two classes, shown below: [Serializable] [XmlInclude(typeof(SomeDerived))] public class SomeBase { public string
I have the below public class Person { // Properties public string Name {
I have two classes below: public class Module { public int Id { get;
I have the code below: public class PatientAgent extends Agent { private final String
I have a class as outlined below: class InputReader { public: typedef void (*handler)(std::string,
I have the code below : public class Anything { public int Data {
I have a data structure which is as given below: class File { public
I have a question, here are two classes below: class Base{ public: virtual void

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.