I want to generate dynamic checkboxes on the basis of selected value of dropdown.
@Html.DropDownListFor(x => x.Fromsource, new SelectList(Model.Fromsource, "Value", "Key"), "---Select---", new
{
})
@Html.CheckBox("Tosource", false, new { @class = "dropdown" })
<script>
$("#Fromsource").change(function () {
var urlSource = '@Url.Action("FillToSource", "PublishPost")';
var fromsouyrcetype = $(this).val();
if (fromsouyrcetype != "") {
$.ajax({
url: urlSource,
method: "GET",
data: {
"sourceType": fromsouyrcetype
},
success: function (result) {
$.each(result, function (index, value) {
//what to write here?
//value.name = name of the checkbox
//value.id = value of the checkbox
});
}
});
} else {
}
});</script>
value.id and value.name are the values which i want to fill for checkbox as mentioned in the comment above.
$('#Tosource').empty();makes no sense (it clears the child elements of the element and a checkbox does not have any). Are you wanting to create multiple checkboxes?