views:

110

answers:

1

I know its possible to accept a list of objects as a parameter thanks to haacked but what about a list of Guids from checkboxes? This is a bit different as the only name you get has to be the ID.

Any help would be greatly appreciated, thanks!

+2  A: 

I'm not sure if you can do Guids this way, since they don't expose a public setter property. I would suggest doing a List and then iterating over the list and using the Guid overload that takes a string:

public ActionResult Foo(IList<string> guidStrings) 
{
   var guids = new List<Guid>();
   foreach(var s in guidStrings)
   {
   guid.Add(new Guid(s));
   }

   return View(guidStrings);
}

Or something like that...

BFree
The issue isn't with List<Guid> but rather whether how it detects the information. If these were simply hidden fields or textboxes, it wouldn't be a problem. But because Checkboxes have 1 name (in this case, it would need to be the value of the Guid) and the value is true/false (or actually, nothing as unchecked boxes don't get pushed back) I don't know if its possible to accept the list.
Chance
Ok, I see what you're saying now. My bad, didn't understand the question. I'll code up some quick samples, and see if I can come up with something.
BFree
Thanks and sorry about the confusion. I'm attempting to do it simply with the form collection but for some strange reason <%=Html.Checkbox(value, bool) not only spits out a checkbox but also a hidden field with the value?
Chance
So they did some funky stuff.. ended up writing my own html <input type="checkbox" name="selectedCategories[<%=i %>]" value="<%=category.ID%>" <%=checkedText %> /> <label for="<%=category.ID %>"><%=category.Name %></label>
Chance