Home > DeveloperSection > Forums > Dynamically Generate checkbox in MVC 4 partial view
Mark Devid
Mark Devid

Total Post:101

Points:707
Posted on    February-02-2013 3:10 AM

 ASP.NET MVC ASP.NET MVC 
Ratings:


 1 Reply(s)
 4045  View(s)
Rate this:

Hi Everyone!

I have to gererate dynamicaly checkbox in MVC 4. How i do this? I have successfuly generated some controls as below code

       <table>

           @foreach (var item in Model)

            {

                <tr>

                    <td>

@*-------------Here i want to put checkbox---------------*@

                    </td>

                    <td>

@Html.DisplayTextFor(m => item.Description)

                    </td>

                </tr>

            }  

        </table>

Thanks in advance




AVADHESH PATEL

Total Post:604

Points:4228
Posted on    February-02-2013 5:25 AM

Hi Mark Devid!

You can try this way

 <table>
            @foreach (var item in Model)
            {
                <tr>
                    <td>
                        @Html.CheckBox("fileItem")
                        @Html.Hidden("fileId", item.ID)
                    </td>
                    <td>
                        @Html.DisplayTextFor(m => item.Description)
                    </td>
                </tr>
            } 
        </table>

I hope, above code will  be resolve your problem


Don't want to miss updates? Please click the below button!

Follow MindStick