Mo
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;namespacemvcapplication8.models{ Public classBrandda {PrivateMasterdatacontext _context =NewMasterdatacontext (); //Search All series PublicList<brand>Select () {return_context.brand.tolist (); } //according to the manufacturer Inquiry series PublicList<brand> Selectbyprod (stringProdcode) { varquery = _context.brand.where (p = = P.prod_code = =Prodcode); returnquery. ToList (); } }}
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;namespacemvcapplication8.models{ Public classCarda {PrivateMasterdatacontext _context =NewMasterdatacontext (); PublicList<car>Select () {return_context.car.tolist (); } //check all models by series PublicList<car> Selectbybrand (stringBrandcode) { varquery = _context.car.where (p = = P.brand = =Brandcode); returnquery. ToList (); } }}
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSYSTEM.WEB.MVC;usingMvcapplication8.models;namespacemvcapplication8.controllers{ Public classCarscontroller:controller {// //GET:/cars/ PublicActionResult Index (stringProdstringBrandstringcar) { //Check all VendorsList<productor> Listprod =NewProductorda (). Select (); //display of the Vendor drop-down tableViewbag.prods =NewSelectList (Listprod,"Prod_code","Prod_name", prod); //through the Vendor query seriesList<brand> Listbrand =NewBrandda (). Selectbyprod (PROD); //Display of Series drop-down tablesViewbag.brands =NewSelectList (Listbrand,"Brand_Code","Brand_Name", Brand); varb = listbrand.exists (p =>p.brand_code = = Brand)? brand:listbrand[0]. Brand_Code; //find the model of a car by seriesList<car> Listcar =NewCarda (). Selectbybrand (b); //the display of the car drop-down tableViewbag.cars =NewSelectList (Listcar,"Code","Name", car); returnView (); } [HttpGet] PublicActionResult Index () {List<Productor> Listprod =NewProductorda (). Select (); Viewbag.prods=NewSelectList (Listprod,"Prod_code","Prod_name","P001"); List<Brand> Listbrand =NewBrandda (). Selectbyprod ("P001"); Viewbag.brands=NewSelectList (Listbrand,"Brand_Code","Brand_Name"); List<Car> Listcar =NewCarda (). Selectbybrand ("b001"); Viewbag.cars=NewSelectList (Listcar,"Code","Name"); returnView (); } }}
@using mvcapplication8.models; @model List<MvcApplication8.Models.Car>@using mvcapplication8.controllers;@{Layout=NULL;}<! DOCTYPE html>"Viewport"Content="Width=device-width"/> <title>Index</title>@using (Html.BeginForm ("Index","Cars", FormMethod.Post)) {@Html. DropDownList ("prod", Viewbag.prods asSelectList,New{onchange="document.forms[0].submit ();"}) @Html. DropDownList ("Brand", Viewbag.brands asSelectList,New{onchange="document.forms[0].submit ();"}) @Html. DropDownList ("Car", Viewbag.cars asselectlist)} <form attion="carscontrollers"Method="Post"> </form> </div></body>
The MVC program develops a linkage query for the vehicle category. Manufacturer, series, model