views:

169

answers:

3

FeatureEvents.bit_Activate = Convert.ToBoolean(collection["bit_Activate"]);

bit_Activate is checkbox ,how would i convert it to boolean above,collection is coming from the formcollection variable

A: 

have you put a watch on the value you are trying to convert to boolean?

I think its most probably that you need to do something like

FeatureEvents.bit_Activate = Convert.ToBoolean(collection["bit_Activate"].checked);
Mauro
Not sure this is going to work. How should the compiler know that `collection["bit_Active"]` has a `.Checked` property? I think you'll need to cast it to some representation of a html checkbox.
Tomas Lycken
A: 

The easiest way to do it is probably by using ASP.NET MVC's built-in ModelBinders, which let you take a CLR object as input to your action, and the MVC framework binds all properties for you. The only requirement is that you (by convention) name your form elements after the properties of the input object. Google "asp.net mvc model binder" for lots of information and tutorials.

Tomas Lycken
A: 

A checkbox input does not appear in the Form collection if unchecked so the following would work for you:

 FeatureEvents.bit_Activate = collection.Keys.Contains["bit_activate"];

Kindness,

Dan

PS: The Html helper for a checkbox eg Html.Checkbox is HORRID it puts a simlarly named hidden input to make sure the element is always in form collection. I find a straight Html <INPUT> works better. If you use the htm helper you will need to parse the array to get the value.

Daniel Elliott