DYNAMICALLY GENERATE CHECKBOX IN MVC 4 PARTIAL VIEW

Mark Devid

Total Post:102

Points:714
Posted by  Mark Devid
 5542  View(s)
Ratings:
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


  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: Dynamically Generate checkbox in MVC 4 partial view

    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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!