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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:57:26+00:00 2026-05-10T19:57:26+00:00

Caution: This question is over nine years old! Your best option is to search

  • 0

Caution: This question is over nine years old!

Your best option is to search for newer questions, or to search the answers below looking for your specific version of MVC, as many answers here are obsolete now.

If you do find an answer that works for your version, please make sure the answer contains the version of MVC you are using.
(The original question starts below)


This seems a bit bizarre to me, but as far as I can tell, this is how you do it.

I have a collection of objects, and I want users to select one or more of them. This says to me ‘form with checkboxes.’ My objects don’t have any concept of ‘selected’ (they’re rudimentary POCO’s formed by deserializing a wcf call). So, I do the following:

public class SampleObject{   public Guid Id {get;set;}   public string Name {get;set;} } 

In the view:

<%     using (Html.BeginForm())     { %>   <%foreach (var o in ViewData.Model) {%>     <%=Html.CheckBox(o.Id)%>&nbsp;<%= o.Name %>   <%}%>   <input type='submit' value='Submit' /> <%}%> 

And, in the controller, this is the only way I can see to figure out what objects the user checked:

public ActionResult ThisLooksWeird(FormCollection result) {   var winnars = from x in result.AllKeys           where result[x] != 'false'           select x;   // yadda } 

Its freaky in the first place, and secondly, for those items the user checked, the FormCollection lists its value as ‘true false’ rather than just true.

Obviously, I’m missing something. I think this is built with the idea in mind that the objects in the collection that are acted upon within the html form are updated using UpdateModel() or through a ModelBinder.

But my objects aren’t set up for this; does that mean that this is the only way? Is there another way to do it?

  • 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. 2026-05-10T19:57:27+00:00Added an answer on May 10, 2026 at 7:57 pm

    Html.CheckBox is doing something weird – if you view source on the resulting page, you’ll see there’s an <input type='hidden' /> being generated alongside each checkbox, which explains the ‘true false’ values you’re seeing for each form element.

    Try this, which definitely works on ASP.NET MVC Beta because I’ve just tried it.

    Put this in the view instead of using Html.CheckBox():

    <% using (Html.BeginForm('ShowData', 'Home')) {  %>   <% foreach (var o in ViewData.Model) { %>     <input type='checkbox' name='selectedObjects' value='<%=o.Id%>'>     <%= o.Name %>   <%}%>   <input type='submit' value='Submit' /> <%}%> 

    Your checkboxes are all called selectedObjects, and the value of each checkbox is the GUID of the corresponding object.

    Then post to the following controller action (or something similar that does something useful instead of Response.Write())

    public ActionResult ShowData(Guid[] selectedObjects) {     foreach (Guid guid in selectedObjects) {         Response.Write(guid.ToString());     }     Response.End();     return (new EmptyResult()); } 

    This example will just write the GUIDs of the boxes you checked; ASP.NET MVC maps the GUID values of the selected checkboxes into the Guid[] selectedObjects parameter for you, and even parses the strings from the Request.Form collection into instantied GUID objects, which I think is rather nice.

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

Sidebar

Related Questions

This may seem like a standard question, but I'm after some 'best practice' here.
Edit: this question was asked due to my misunderstanding. Proceed with caution, as reading
I know this question has been around, but I found answers a bit foggy,
This wasn't the question I was going to ask but I have unexpectedly run
This is probably the dumbest question ever here on stack Overflow. But I am
The question is similar to this one: How to display a content in two-column
Head's up: This question is related to the recent deprecation of viewDidUnload . I
I have this question on the Wordpress stack exchange as well, but not having
Following up on this question, I'm working on a large Delphi 7 codebase which
I'm almost certain I know the answer to this question, but I'm hoping there's

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.