$("#CategoryID").change(function () {
var id = $("#CategoryID").val();
var url = '/SuperAdmin/Home/GetSubCatList';
debugger
$.ajax({
type: "POST",
url: url,
cache: false,
data: {ID : id},
success: function (result) {
var items = '';
$("#SubCategoryID").empty();
$.each(result, function (i, subcategory) {
items += "<option value='" + subcategory.value + "'>" + subcategory.text + "</option>";
});
$('#SubCategoryID').html(items);
},
error: function (result) {
alert('Oh no aa :(' + result[0]);
}
});
And My Controller Action is:
[HttpPost]
public ActionResult GetSubCatList(int ID)
{
List<SubCategory> subCategorylist = new List<SubCategory>();
//// ------- Getting Data from Database Using EntityFrameworkCore -------
subCategorylist = (from subcategory in _db.SubCategory
where subcategory.CategoryID == ID
select subcategory).ToList();
return Json(new SelectList(subCategorylist, "SubCategoryID", "SubCategoryTitle"));
}
app.UseMvc(routes =>
{
routes.MapRoute(
name: "areas",
template: "{area:exists}/{controller=Home}/{action=Index}/{id?}"
);
routes.MapRoute(
name: "default",
template: "{action}/{id?}",
defaults: new { controller = "Home", action = "Index" });
});