Home query All collections of the first Level menu list, take the first level of the subscript, according to the first subscript query the second level collection.
This displays the two dropdown select menu on the page, which is the first one queried from the database by default.
According to the drop-down box to select the corresponding second-level data, on the page need to write an Ajax submission method,
$ (function () {
$ (' #sltCampus '). On (' Change ', function () {
$.ajax ({
Type: "POST",
URL: '/member/getrestaurant ',
Data: {campusid: $ (this). Val ()},
DataType: "JSON",
Success:function (obj) {
if (obj. Result) {
var html = ';
for (var i = 0; i < obj. List.length; i++) {
HTML + = ' <option value= ' + obj. List[i]. Restaurantid + ' > ' + obj. List[i]. Name + ' </option> ';
}
alert (HTML);
$ (' #sltRest '). HTML (HTML);
}
}
});
});
The method is submitted to the Controller method, which is based on the Campusid to get the second level of the collection.
if (Xre.list (Campusid, out resturant))
{
Xlog.addline ("List Success.");
var list = resturant. Select (x = new
{
Restaurantid = X.restaurantid,
Name = X.name,
});//Projection
Return Json (New {Result = true, List = list});
}
How to add a dropdown frame linkage effect in ASP. NET MVC