I have 2 dropdown
a) Category
b) SubCategory
I need to load Sub Categories on change of Category, but Controller action is never fired and I receive jquery error
Uncaught TypeError: Cannot read property 'toLowerCase' of undefined
SuperAdmin is My Area.
My jQuery action syntax is:
$("#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 += "";
});
$('#SubCategoryID').html(items);
},
error: function (result) {
alert('Oh no aa :(' + result[0]);
}
});
And My Controller Action is:
[HttpPost]
public ActionResult GetSubCatList(int ID)
{
List subCategorylist = new List();
//// ------- 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"));
}
My Route Setting in Startup is:
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" });
});
please suggest a solution.
Jignesh KumarPosted Jun 10, 2021, 3:36 AM
Dhanesh KumarPosted Jun 9, 2021, 8:08 PM
data:"ID=" + id
if you have multiple then use
data:"ID=" + id&"p1=xx&p2=yy"
'application/x-www-form-urlencoded; charset=UTF-8
Sachin SinghPosted Aug 9, 2020, 1:02 AM