The Query method in model
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;namespacemvcapplication Routing contact. models{ Public classCARBF {PrivateMastercardatacontext _context =NewMastercardatacontext (); PublicList<car>Select () {return_context.car.tolist (); } PublicList<car> Selectbybrand (stringBrandcode) { varQuery=_context.car.where (p=>p.brand==Brandcode); returnquery. ToList (); } PublicList<car> Selecbyprice (decimalLowdecimalupp) { varquery = _context.car.where (P=>p.price>=low &&p.price<=upp); returnquery. ToList (); } }}
The code in the controller
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSYSTEM.WEB.MVC;usingmvcapplication routing contact. Models;namespacemvcapplication Routing contact. controllers{ Public classHomecontroller:controller {// //GET:/home/ PublicActionResult Index () {returnView (); } PublicActionResult Findbyprice (decimalLowdecimalupp) {List<Car> list =NewCARBF (). Selecbyprice (Low,upp); returnView (list); } }}
Two views of the code
@{Layout=NULL;}<! DOCTYPE html>"Viewport"Content="Width=device-width"/> <title>Index</title>@using (Html.BeginForm ("Findbyprice","Home", FormMethod.Post)) { <div>highest Price: @Html. TextBox (" Low"); Lowest Price: @Html. TextBox ("upp"); </div> <input id="Submit1"Type="Submit"Value="Enquiry"/> } </div></body>@using mvcapplication routing contact. Controllers; @using mvcapplication routing contact. Models; @model List<Car>@{Layout=NULL;}<! DOCTYPE html>"Viewport"Content="Width=device-width"/> <title>Findbyprice</title>@foreach (Car datainchModel) { <li>@[email protected]</li> } </ol> </div></body> MVC route Query, what is the role of routing exactly??