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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:35:09+00:00 2026-05-24T10:35:09+00:00

I am trying to put a checkboxlist onto a simple form in asp.NET MVC

  • 0

I am trying to put a checkboxlist onto a simple form in asp.NET MVC 2. This is the code for it:

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <% using (Html.BeginForm("HandSurvey", "Resources", FormMethod.Post, new { runat="server" }))
        { %>
            <asp:CheckBoxList id="chkListChemical" runat="server">
                <asp:ListItem>Fiberglass & resins</asp:ListItem>
                <asp:ListItem>Heavy duty oil paints & stains</asp:ListItem>
                <asp:ListItem>Mechanics - tools, grease/oil</asp:ListItem>
                <asp:ListItem>Metalworking fluids</asp:ListItem>
                <asp:ListItem>Paint & Stains in use</asp:ListItem>
                <asp:ListItem>Exposure to solvents</asp:ListItem>
                <asp:ListItem>Difficult soils</asp:ListItem>
                <asp:ListItem>Hydrocarbons</asp:ListItem>
            </asp:CheckBoxList>
        <% } 
    %>
</asp:Content>

When I hit this page it gives this error:

Control ‘ctl00_MainContent_chkListChemical_0’ of type ‘CheckBox’ must be placed inside a form tag with runat=server.

I thought I was specifying the runat attribute correctly. Or is there something else that I am missing here? If I don’t use the helper class and just use a regular form tag, it works.

  • 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-05-24T10:35:12+00:00Added an answer on May 24, 2026 at 10:35 am

    In ASP.NET MVC you should avoid using server controls. Basically everything that has the runat="server" should not be used (except the content placeholder in WebForms view engine). In ASP.NET MVC you design view models:

    public class MyViewModel
    {
        [DisplayName("Fiberglass & resins")]
        public bool Item1 { get; set; }
    
        [DisplayName("Heavy duty oil paints & stains")]
        public bool Item2 { get; set; }
    
        ...
    }
    

    then you have controller actions that manipulate the view model:

    // Action that renders the view
    public ActionResult Index()
    {
        var model = new MyViewModel();
        return View(model);
    }
    
    // Handles the form submission
    [HttpPost]
    public ActionResult Index(MyViewModel model)
    {
        // TODO: Process the results
        return View(model);
    }
    

    and finally you have a strongly typed view:

    <% using (Html.BeginForm("HandSurvey", "Resources")) { %>
        <div>
             <%= Html.CheckBoxFor(x => x.Item1) %> 
             <%= Html.LabelFor(x => x.Item1) %>
        </div>
        <div>
             <%= Html.CheckBoxFor(x => x.Item2) %> 
             <%= Html.LabelFor(x => x.Item2) %>
        </div>
    
        ...
    
        <p><input type="submit" value="OK" /></p>
    <% } %>
    

    UPDATE:

    As requested in the comments section in order to have those checkboxes dynamically generated from a database it is a simple matter of adapting our view model:

    public class ItemViewModel
    {
        public int Id { get; set; }
        public string Text { get; set; }
        public bool IsChecked { get; set; }
    }
    

    and now we will have our controller action to return a list of this view model:

    public ActionResult Index()
    {
        // TODO: obviously those will come from a database
        var model = new[]
        {
            new ItemViewModel { Id = 1, Text = "Fiberglass & resins" },
            new ItemViewModel { Id = 2, Text = "Heavy duty oil paints & stains" },
        };
        return View(model);
    }
    

    and the view will now simply become:

    <% using (Html.BeginForm("HandSurvey", "Resources")) { %>
        <%= Html.EditorForModel() %>
        <p><input type="submit" value="OK" /></p>
    <% } %>
    

    and the last part would be to define an editor template for our view model (~/Views/Shared/EditorTemplates/ItemViewModel.ascx):

    <%@ Control 
        Language="C#"
        Inherits="System.Web.Mvc.ViewUserControl<AppName.Models.ItemViewModel>" 
    %>
    <div>
        <%= Html.HiddenFor(x => x.Id) %>
        <%= Html.CheckBoxFor(x => x.IsChecked) %>
        <%= Html.DisplayFor(x => x.Text) %>
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

trying to put a strongly typed partial view on a homepage in asp.net but
I am trying to put some distributed caching into play, I'm using this indeXus.Net
I'm trying to put together a simple RSS widget (for my wordpress blog) that
I am trying to put a PSD file on my form using Microsoft report
I'm trying to put together a presentation for my local .NET user group on
I'm trying to put together this layout... ... but I'm having issues with the
I'm trying to put into XML-file some data. Here is the code: @Test public
Am trying to put together a form validation script, and i hit a snag
I am trying to put form into help mode in Delphi 2010. I have
I am trying to put the content of an NSDictionary into an NSString for

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.