javascript - cannot call json result using jquery -



javascript - cannot call json result using jquery -

c# , jquery,

i have 2 drop-down lists(category , product), , have alter product list based on category.

@html.dropdownlist("categoryid", new selectlist(viewbag.category, "id", "name"), "select parent category", new { @class = "form-control categorydata" }) @html.dropdownlist("productid", new selectlist(viewbag.product, "id", "name"), "select product", new { @class = "form-control product-list" })

and writing next controller getting products list.it worked.

[httpget] public jsonresult getproducts(int categoryid) { int tot = new products().total; int cont = 1; category cat = new category(2); var products = new products(cont, tot, cat); // viewbag.products = new products(1,new products().total,new category(categoryid)); homecoming json(products); }

and jquery is,

$('.categorydata').change(function () { var selcat = $(".categorydata").val(); var url = "~/add/getproducts"; if (selcat.length != 0) { $.get(url, { id: selcat }, function (data) { alert(data); }); } });

this jquery didn't phone call controller, , can not info .

please help me solve it.

you should maintain property name in json info same parameter name of action method.

$.get(url, { categoryid : selcat }, function (data) {

refer so post.

javascript c# jquery json asp.net-mvc-4

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -