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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:28:55+00:00 2026-06-04T04:28:55+00:00

I have an MVC view <%@ Page Language=C# MasterPageFile=PathToMaster Inherits=System.Web.Mvc.ViewPage<ModelData> %> and I have

  • 0

I have an MVC view

<%@ Page Language="C#" MasterPageFile="PathToMaster" Inherits="System.Web.Mvc.ViewPage<ModelData>" %>

and I have a form with HTML markup for a set of checkboxes:

<label for="MyCheckbox">Your choice</label>
<input type="checkbox" id="Option1" class="checkbox" name="MyCheckbox" value="Option one" />
<label for="Option1">Option one</label><br />
<input type="checkbox" id="Option2" class="checkbox" name="MyCheckbox" value="Option two" />
<label for="Option2">Option two</label><br />

and I have a controller-action pair

class MyController : Controller {
    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult RequestStuff( ModelData data )
    {
    }
}

and that action is invoked when the form is submitted.

How do I map the checkboxes onto members of ModelData (and what members I have to add to ModelData) so that when the form is submitted data stores information on which checkboxes are checked?

  • 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-04T04:28:55+00:00Added an answer on June 4, 2026 at 4:28 am

    OK, this one will be for MVC3, but – save for syntax changes – should work in MVC2 too. The approach is essentially the same.

    First of all, you should prepare an appropriate (view)model

    public class MyViewModel
    {
        [DisplayName("Option 1")]
        public bool Option1 { get; set; }
    
        [DisplayName("Option 2")]
        public bool Option2 { get; set; }
    }
    

    Then you pass this model to the view you’re showing (controller):

    public ActionResult EditMyForm()
    {
        var viewModel = new MyViewModel()
        return View(viewModel);
    }
    

    with the form:

    @model MyViewModel
    @using( Html.BeginForm())
    {
        @Html.Label("Your choice")
    
        @Html.LabelFor(model => model.Option1) // here the 'LabelFor' will show you the name you set with DisplayName attribute
        @Html.CheckBoxFor(model => model.Option1)
    
        @Html.LabelFor(model => model.Option2)
        @Html.CheckBoxFor(model => model.Option2)
        <p>
            <input type="submit" value="Submit"/>
        </p>
    }
    

    Now here the HTML helpers (all the CheckBoxFor, LabelFor, EditorFor etc) allow to bind the data to the model properties.

    Now mind you, an EditorFor when the property is of type bool will give you the check-box in the view, too. 🙂

    And then, when you submit to the controller, it will auto-bind the values:

    [HttpPost]
    public ActionResult EditMyForm(MyViewModel viewModel)
    {
        //And here the view model's items will be set to true/false, depending what you checked.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple view: <%@ Page Title= Language=C# MasterPageFile=~/Views/Shared/Site.Master Inherits=System.Web.Mvc.ViewPage %> <asp:Content ID=Content1
I have a view that is strongly typed: <%@ Page Title= Language=C# MasterPageFile=~/Views/Shared/Site.Master Inherits=System.Web.Mvc.ViewPage<MPKwithMVC.Models.SmartFormViewModel>
I have my main view like this: <%@ Page Title= Language=C# MasterPageFile=~/Views/Shared/Site.Master Inherits=System.Web.Mvc.ViewPage %>
I have a main page which looks like: <%@ Page Title= Language=C# MasterPageFile=~/Views/Shared/Site.Master Inherits=System.Web.Mvc.ViewPage
I have HTML table on the ASP.NET MVC View page. Now I have to
I have the following header of ASP.Net MVC page: <%@ Page Title= Language=C# MasterPageFile=~/Views/Shared/Admin.Master
I have included the below in my MVC View page <%@ Page Title= Language=C#
I have a drop-down list hardcoded in an MVC View User Control page and
Using ASP MVC and Entity Framework. In the view, you have a page declaration
I have two classes (MVC view model) which inherits from one abstract base class.

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.