<table>
<tr>
<td>Category
</td>
<td>
<select id="Category"></select>
</td>
</tr>
<tr>
<td>Subcategory
</td>
<td>
<select id="SubCategory"></select>
</td>
</tr>
</table>
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
url: '/ControllerName/GetAllCategory', type: 'Get', dataType: 'json',
success: function (data) {
var categoryObj = $('#Category');
categoryObj.empty();
$.each(data, function (i, entity) {
categoryObj.append('<option value="' + entity.Id + '">' + entity.Name + '</option>');
});
}
});
$('#Category').change(function () {
$('#SubCategory').empty();
if ($(this).val() != null && $(this).val() != 0) {
$.ajax({
url: '/ControllerName/GetAllSubCategory', type: 'Get', dataType: 'json',
data: { CategoryId: $(this).val() },
success: function (data) {
var subCategoryObj = $('#SubCategory');
//subCategoryObj.empty();
$.each(data, function (i, entity) {
subCategoryObj.append('<option value="' + entity.Id + '">' + entity.Name + '</option>');
});
}
});
}
});
});
</script>