Click here to Skip to main content
16,007,885 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am creating an application in asp.net MVC 3
I should have multiple check boxes on my View

I have a model class and based on it i am generating my View the problem is arising with multiple Check box

here is my Model class

C#
public class FormModel
   {
       public string ID { get; set; }
       public int No { get; set; }
       public string type { get; set; }
       public string value { get; set; }

       public string[] Ctype //Multiple Check Boxes
       {
           get;
           set;
       }

   }

and on View i am using this


<table>
    <tr>
    <td>Enter ID:</td>
    <td> @Html.TextBoxFor(m => m.ID)</td>
    </tr>
    <tr>
    <td>Enter Number of controls wanted:</td>
    <td>@Html.TextBoxFor(m => m.No)</td>
    </tr>
    <tr>
    <td>Select type of control:</td>
    <td> @Html.DropDownListFor(m => m.type,items)</td>    
    <td>@Html.CheckBoxFor(m=> m.Ctype)</td>
    </tr>
    <tr>
    <td>Value:</td>
    <td>@Html.TextBoxFor(m => m.value)</td>

m is the reference of model class
</tr></table>


The problem is arising at CheckBoxFor, it is saying that cannot implicitly convert string[] to bool


Can any one help me out on this
Posted

1 solution

Hi,

You can only take CheckBoxFor when you have bool value. Or else you can use Simply Checkbox for the same.

For your solution you can generate multiple checkboxes with use of "CheckBox" instead of "CheckBoxFor"

Regards,
Sagar Solanki
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900