Pull-down list linkage display (car table) three-level linkage

Source: Internet
Author: User

1, Modelsnamespacethe drop-down list displays the _car table _. models{ Public classPRODUCTORBF {PrivateMydbdatacontext _context=NewMydbdatacontext ();  PublicList<productor> Select ()//All Manufacturers Show        {            return_context.productor.tolist (); }    }}namespacethe drop-down list displays the _car table _. models{ Public classbrandbf {PrivateMydbdatacontext _context =NewMydbdatacontext ();  PublicList<brand> Select ()//Brand (series) Show All        {            return_context.brand.tolist (); }         PublicList<brand> Selectbyprod (stringProd//Check car brands according to auto manufacturers        {            varquery = _context.brand.where (P = = P.prod_code = =prod); if(Query. Count () >0)            {                returnquery.            ToList (); }            Else            {                return NULL; }                 }    }}namespacethe drop-down list displays the _car table _. models{ Public classCARBF {PrivateMydbdatacontext _context =NewMydbdatacontext ();  PublicList<car> Select ()//All Cars Show        {            return_context.car.tolist (); }         PublicList<car> Selectbybrand (stringBrand_Code)//Check specific cars according to car brands        {            varquery = _context.car.where (P = = p.brand==Brand_Code); if(Query. Count () >0)            {                returnquery.            ToList (); }            Else            {                return NULL; }        }    }}2, Controllersnamespacethe drop-down list displays the _car table _. controllers{ Public classHomecontroller:controller {[HttpGet] PublicActionResult Index () {//Manufacturers table (strong type)list<productor> list =NewPRODUCTORBF ().            Select (); SelectList AAA=NewSelectList (list,"Prod_code","Prod_name","P001"); //Brand TableList<brand> List1 =NewBRANDBF (). Selectbyprod ("P001"); SelectList BBB1=NewSelectList (List1,"Brand_Code","Brand_Name"); VIEWBAG.BBB=BBB1; //Car WatchList<car> cars =NewCARBF (). Selectbybrand ("b001"); SelectList CCC1=NewSelectList (Cars,"Code","name"); VIEWBAG.CCC=ccc1; returnView (AAA); } [HttpPost] PublicActionResult Index (stringProdcode,stringBrandcode,stringCarcode) {              //Manufacturers table (strong type)List<productor> List1 =NewPRODUCTORBF ().            Select (); SelectList AAA=NewSelectList (List1,"Prod_code","Prod_name", Prodcode); //Brand TableList<brand> List2 =Newbrandbf ().             Selectbyprod (Prodcode); SelectList BBB1=NewSelectList (List2,"Brand_Code","Brand_Name", Brandcode); VIEWBAG.BBB=BBB1; //Car Watch//Two cases: Choose the manufacturer, judge the load of the series is not under the current manufacturer//1, in the words, directly according to the series Code load//2, not in the case, according to the newly selected manufacturers to load out the series of the first check            varb = List2. Exists (P = P.brand_code = = Brandcode)? brandcode:list2[0].brand_code;//assuming the choice is P003, but the positioning of brand is B001, all need to judge, if the brand in the drop-down list there is a code in the name of the incoming brands, the explanation is, you can check, if not included, you need to submit to the manufacturer of the brand identified in the firstList<car> List3 =NewCARBF ().            Selectbybrand (b); SelectList CCC1=NewSelectList (List3,"Code","name", Carcode); VIEWBAG.CCC=ccc1; returnView (AAA); }    }}3, views@using drop-down list linkage display _car table _. Models, @model selectlist @{Layout=NULL;}<! DOCTYPE html>"Viewport"Content="Width=device-width"/> <title>Index</title>@using (Html.BeginForm ("Index","Home", FormMethod.Post)) {           //new {onchange= "document.forms[0].submit ();"} Once the text changes the entire form will change@Html. DropDownList ("Prodcode", Model,New{onchange="document.forms[0].submit ();"}); @Html. DropDownList ("Brandcode", VIEWBAG.BBB asSelectList,New{onchange="document.forms[0].submit ();"}); @Html. DropDownList ("Carcode", VIEWBAG.CCC asselectlist); }    </div></body>

Drop-down list linkage display (car table) three-level linkage

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.