tags:

views:

82

answers:

3

Hi, I have found a lot of tutorial on ASP.NET MVC. But most of the tutorials have skiped the use of check box and radio button html helpers. I need some tutorials on them.

*** I have a field in Data model called "Checked". Now how can i verify that in my form view it is checked or unchecked?

A: 

I have just had such a problem, and I decided to skip it entirely by entering my own HTML for the checkbox.

You either add the checkbox as a parameter to your action, and then it will be handled for you entirely, or maybe you'd better type in the HTML directly.

The helper for the checkboxes will in fact generate not one, but TWO checkboxes for every single call. This is because an unchecked checkbox will NOT be present in the POSTed form, and therefore it may be impossible to know whether a data is absent, or has been unchecked.

It depends on your model whether this is a problem to you. If you don't put a parameter to the atcion just for the checkbox, you will receive a string value such as:

"{true,false}"

that is two values: the current one (the new one), and the previous one (the one before user's interaction). You'd then need to parse this string to get the actual value.

To put a parameter, you can check the LogOn action in the AccountController which is generated in the starting project for MVC in Visual Studio.

Palantir
A: 

Check my answers on checkbox from checkbox

Radio buttons are same as html input button, nothing new..

Gabriel Susai
A: 

Thanks Palantir. I just solved my problem. I add check box as a parameter of controller's action method and it works!