0

I am working in MVC 4, and in my View i am writing this code to generate the checkbox:

<tr class="formSectionField clearfix">
   <td>
      <label id="lblStoreList" class="formSectionLabel">Title:</label>
   </td>
   <td>
     <div class="txtInput input323">
        @Html.CheckBoxFor(m => m.StoreList, new SelectList(Enumerable.Empty<SelectListItem>()))
     </div>
   </td>
</tr>

Initially, i am just telling MVC framework, that it will have a checbox, but i want to have n number of checkbox based upon the value that is contained in my model.

How could i achieve that?

Below is the JS code with AJAX which will generate my dynamic checkbox:

function BindTitle() {
    $.ajax({
        "url": "/Admin/GetTitleList/",
        "type": "get",
        "dataType": "json",
        "success": function (data) {
            var items = $('#TitleId');
            items.empty();
            $.each(data, function (i, drdData) {
                items.append($('<checkbox/>', { value: drdData.Value, html: drdData.Text }));
            });
        }
    });
}

Hope i made you clear with this, in any case if you want further suggestion, please feel free to ask

tereško
  • 58,060
  • 25
  • 98
  • 150
HarshSharma
  • 630
  • 3
  • 9
  • 34

0 Answers0