controller
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MODEL;
using BLL;
namespace YYS.WeekTest1.Controllers
{
public class HomeController : Controller
{
ZhpBLL<ZhpMODEL> bll = new ZhpBLL<ZhpMODEL>();
ZhpBLL<CarMODEL> blls = new ZhpBLL<CarMODEL>();
//展示商品
public ActionResult GetList(string age, string bian, string xing, string cheng, string pai, string zhun, string zuo, string you)
{
List<CarMODEL> list = blls.GetList("Car");
var AgeList = list.Where(m => (!string.IsNullOrWhiteSpace(age) ? m.Age.Contains(age) : true));
var BianList = AgeList.Where(m => (!string.IsNullOrWhiteSpace(bian) ? m.Bian.Contains(bian) : true));
var XingList = BianList.Where(m => (!string.IsNullOrWhiteSpace(xing) ? m.Xing.Contains(xing) : true));
var ChengList = XingList.Where(m => (!string.IsNullOrWhiteSpace(cheng) ? m.Cheng.Contains(cheng) : true));
var PaiList = ChengList.Where(m => (!string.IsNullOrWhiteSpace(pai) ? m.Pai.Contains(pai) : true));
var ZhunList = PaiList.Where(m => (!string.IsNullOrWhiteSpace(zhun) ? m.Zhun.Contains(zhun) : true));
var ZuoList = ZhunList.Where(m => (!string.IsNullOrWhiteSpace(zuo) ? m.Zuo.Contains(zuo) : true));
var YouList = ZuoList.Where(m => (!string.IsNullOrWhiteSpace(you) ? m.You.Contains(you) : true)).ToList();
return View(YouList);
}
//品牌
public JsonResult Pai(string TableName="ZHP") {
return Json(bll.GetList(TableName).Where(m => m.CarType == 10).ToList());
}
//型号
public JsonResult Xing(string TableName = "ZHP")
{
return Json(bll.GetList(TableName).Where(m => m.CarType == 11).ToList());
}
//价格
public JsonResult Price(string TableName = "ZHP")
{
return Json(bll.GetList(TableName).Where(m => m.CarType == 12).ToList());
}
//车龄
public JsonResult Age(string TableName = "ZHP")
{
return Json(bll.GetList(TableName).Where(m => m.CarType == 1).ToList());
}
//变速箱
public JsonResult Bian(string TableName = "ZHP")
{
return Json(bll.GetList(TableName).Where(m => m.CarType == 2).ToList());
}
//车型
public JsonResult CarXing(string TableName = "ZHP")
{
return Json(bll.GetList(TableName).Where(m => m.CarType == 3).ToList());
}
//里程
public JsonResult Cheng(string TableName = "ZHP")
{
return Json(bll.GetList(TableName).Where(m => m.CarType == 4).ToList());
}
//排量
public JsonResult PaiLiang(string TableName = "ZHP")
{
return Json(bll.GetList(TableName).Where(m => m.CarType == 5).ToList());
}
//排放标准
public JsonResult Zhun(string TableName = "ZHP")
{
return Json(bll.GetList(TableName).Where(m => m.CarType == 7).ToList());
}
//座位数
public JsonResult Zuo(string TableName = "ZHP")
{
return Json(bll.GetList(TableName).Where(m => m.CarType == 8).ToList());
}
//燃油类型
public JsonResult You(string TableName = "ZHP")
{
return Json(bll.GetList(TableName).Where(m => m.CarType == 9).ToList());
}
}
}
View
GetList
@model IEnumerable<MODEL.CarMODEL>
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>GetList</title>
<link href="~/Content/bootstrap.css" rel="stylesheet" />
<script src="~/Scripts/jquery-3.3.1.js"></script>
<script>
$(function () {
$.post("/Home/Pai", function (list) {
for (var i = 0; i < list.length; i++) {
$("#Pai").append("<td>" + list[i].CarTypeName + "</td>");
}
})
$.post("/Home/Xing", function (list) {
for (var i = 0; i < list.length; i++) {
$("#Xing").append("<td>" + list[i].CarTypeName + "</td>");
}
})
$.post("/Home/Price", function (list) {
for (var i = 0; i < list.length; i++) {
$("#Price").append("<td>" + list[i].CarTypeName + "</td>");
}
})
//车龄
$.post("/Home/Age", function (list) {
for (var i = 0; i < list.length; i++) {
$("#Age").append("<option>" + list[i].CarTypeName+"</option>");
}
})
//车龄
$.post("/Home/Bian", function (list) {
for (var i = 0; i < list.length; i++) {
$("#Bian").append("<option>" + list[i].CarTypeName + "</option>");
}
})
//车型
$.post("/Home/CarXing", function (list) {
for (var i = 0; i < list.length; i++) {
$("#CarXing").append("<option>" + list[i].CarTypeName + "</option>");
}
})
//里程
$.post("/Home/Cheng", function (list) {
for (var i = 0; i < list.length; i++) {
$("#Cheng").append("<option>" + list[i].CarTypeName + "</option>");
}
})
//排量
$.post("/Home/PaiLiang", function (list) {
for (var i = 0; i < list.length; i++) {
$("#PaiLiang").append("<option>" + list[i].CarTypeName + "</option>");
}
})
//排放标准
$.post("/Home/Zhun", function (list) {
for (var i = 0; i < list.length; i++) {
$("#Zhun").append("<option>" + list[i].CarTypeName + "</option>");
}
})
//座位数
$.post("/Home/Zuo", function (list) {
for (var i = 0; i < list.length; i++) {
$("#Zuo").append("<option>" + list[i].CarTypeName + "</option>");
}
})
//燃油类型
$.post("/Home/You", function (list) {
for (var i = 0; i < list.length; i++) {
$("#You").append("<option>" + list[i].CarTypeName + "</option>");
}
})
})
</script>
</head>
<body>
<form action="/Home/GetList" method="post">
<table class="table">
<tr id="Pai">
<td>品牌</td>
</tr>
<tr id="Xing">
<td>车型</td>
</tr>
<tr id="Price">
<td>价格</td>
</tr>
<tr id="Duo">
<td>更多</td>
<td>
<select id="Age" name="age">
<option value=" ">车龄</option>
</select>
</td>
<td>
<select id="Bian" name="bian">
<option value=" ">变速箱</option>
</select>
</td>
<td>
<select id="CarXing" name="xing">
<option value=" ">车型</option>
</select>
</td>
<td>
<select id="Cheng" name="cheng">
<option value=" ">里程</option>
</select>
</td>
<td>
<select id="PaiLiang" name="pai">
<option value=" ">排量</option>
</select>
</td>
<td>
<select id="Zhun" name="zhun">
<option value=" ">排量标准</option>
</select>
</td>
<td>
<select id="Zuo" name="zuo">
<option value=" ">座位数</option>
</select>
</td>
<td>
<select id="You" name="you">
<option value=" ">燃油类型</option>
</select>
</td>
</tr>
</table>
<input id="Submit1" type="submit" value="立即查询" />
</form>
<h2>全部</h2>
@foreach (var item in Model)
{
<table class="table" style="200px;float:left">
<tr>
<td>@Html.DisplayFor(modelItem => item.Pai)@Html.DisplayFor(modelItem => item.Xi)@Html.DisplayFor(modelItem => item.Xing)</td>
</tr>
<tr>
<td>
<img src=@item.Img />
</td>
</tr>
<tr>
<td>
@Html.DisplayFor(modelItem => item.Age)| @Html.DisplayFor(modelItem => item.Cheng)
</td>
</tr>
</table>
}
</body>
</html>