How to add a dropdown frame linkage effect in ASP. NET MVC

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.