// GET: Main public ActionResult Index() { var cityId = FrontUtils.GetCityId(HttpContext); string cityName = cityService.GetById(cityId).Name; ViewBag.CityName = cityName; var cities = cityService.GetAll(); return(View(cities)); }
public ActionResult Index() { //一定能拿到一个CityId long cityId = FrontUtils.GetCityId(HttpContext); string cityName = cityService.GetById(cityId).Name; ViewBag.cityName = cityName; //不用ViewBag,后面需要改成ViewModel var cities = cityService.GetAll(); return(View(cities)); }
/// <summary> /// 加载数据 /// </summary> /// <param name="typeId"></param> /// <param name="keyWords"></param> /// <param name="monthRent"></param> /// <param name="orderByType"></param> /// <param name="regionId"></param> /// <param name="pageIndex"></param> /// <returns></returns> public ActionResult LoadMore(long typeId, string keyWords, string monthRent, string orderByType, long?regionId, int pageIndex) { //获取城市Id long cityId = FrontUtils.GetCityId(HttpContext); HouseSearchOptions searchOpt = new HouseSearchOptions(); searchOpt.CityId = cityId; searchOpt.CurrentIndex = pageIndex; //根据月租金 int?startMonthRent; int?endMonthRent; ParseMonthRent(monthRent, out startMonthRent, out endMonthRent); searchOpt.EndMonthRent = endMonthRent; searchOpt.StartMonthRent = startMonthRent; //搜索 searchOpt.Keywords = keyWords; //根据orderByType排序规则搜索 switch (orderByType) { case "MonthRentAsc": searchOpt.OrderByType = HouseSearchOrderByType.MonthRentAsc; break; case "MonthRentDesc": searchOpt.OrderByType = HouseSearchOrderByType.MonthRentDesc; break; case "AreaAsc": searchOpt.OrderByType = HouseSearchOrderByType.AreaAsc; break; default: searchOpt.OrderByType = HouseSearchOrderByType.AreaDesc; break; } searchOpt.PageSize = 10; searchOpt.RegionId = regionId; searchOpt.TypeId = typeId; //开始搜索 var searchResult = houseService.Search(searchOpt);//搜索结果 var houses = searchResult.result; return(Json(new AjaxResult() { Status = "ok", Data = houses })); }
public ActionResult Search(long typeId, string keyWords, string monthRent, string orderByType, long?regionId) { //获得当前城市的Id long cityId = FrontUtils.GetCityId(HttpContext); HouseSearchViewModel model = new Modals.HouseSearchViewModel(); //获取这个cityId城市下所有的区域 model.regions = regionService.GetAll(cityId); HouseSearchOptions searchOpt = new HouseSearchOptions(); searchOpt.CityId = cityId; searchOpt.CurrentIndex = 1; //根据月租金 int?startMonthRent; int?endMonthRent; ParseMonthRent(monthRent, out startMonthRent, out endMonthRent); searchOpt.EndMonthRent = endMonthRent; searchOpt.StartMonthRent = startMonthRent; //搜索 searchOpt.Keywords = keyWords; //根据orderByType排序规则搜索 switch (orderByType) { case "MonthRentAsc": searchOpt.OrderByType = HouseSearchOrderByType.MonthRentAsc; break; case "MonthRentDesc": searchOpt.OrderByType = HouseSearchOrderByType.MonthRentDesc; break; case "AreaAsc": searchOpt.OrderByType = HouseSearchOrderByType.AreaAsc; break; default: searchOpt.OrderByType = HouseSearchOrderByType.AreaDesc; break; } searchOpt.PageSize = 10; searchOpt.RegionId = regionId; searchOpt.TypeId = typeId; //开始搜索 var searchResult = houseService.Search(searchOpt);//搜索结果 model.Houses = searchResult.result; return(View(model)); }
//服务器端分页加载 //long typeId,string keyWords, string monthRent, string orderByType, long? regionId //都是搜索条件,从QueryString中获取 public ActionResult Search(long typeId, string keyWords, string monthRent, string orderByType, long?regionId) { //根据Session中保存的用户Id获得用户所在城市Id long cityId = FrontUtils.GetCityId(HttpContext); //取得城市下所有区域 var regions = regionService.GetAll(cityId); //把用户所在城市区域传给界面 HouseSearchViewModel model = new HouseSearchViewModel(); model.Regions = regions; //动态构造HouseSearchOptions对象 HouseSearchOptions searchOpt = new HouseSearchOptions(); searchOpt.CityId = cityId; searchOpt.CurrentIndex = 1; //解析月租部分 int?startMonthRent; int?endMonthRent; //ref/out ParseMonthRent(monthRent, out startMonthRent, out endMonthRent); searchOpt.EndMonthRent = endMonthRent; searchOpt.StartMonthRent = startMonthRent; //关键字 searchOpt.Keywords = keyWords; //解析排序规则 switch (orderByType) { case "MonthRentAsc": searchOpt.OrderByType = HouseSearchOrderByType.MonthRentAsc; break; case "MonthRentDesc": searchOpt.OrderByType = HouseSearchOrderByType.MonthRentDesc; break; case "AreaAsc": searchOpt.OrderByType = HouseSearchOrderByType.AreaAsc; break; case "AreaDesc": searchOpt.OrderByType = HouseSearchOrderByType.AreaDesc; break; } searchOpt.PageSize = 10; searchOpt.RegionId = regionId; searchOpt.TypeId = typeId; //开始搜索 var searchResult = houseService.Search(searchOpt); //搜索结果 model.houses = searchResult.result; return(View(model)); }
/// <summary> /// 展示搜索的页面 /// </summary> /// <param name="typeId"></param> /// <param name="keyWords">关键字</param> /// <param name="monthRent">价格区间</param> /// <param name="orderByType">排序规则</param> /// <param name="regionId">区域id</param> /// <returns></returns> public ActionResult Search(long typeId, string keyWords, string monthRent, string orderByType, long?regionId) { //获得当前用户城市Id long cityId = FrontUtils.GetCityId(HttpContext); //获取城市下所有区域 var regions = regionService.GetAll(cityId); HouseSearchViewModel model = new HouseSearchViewModel(); model.regions = regions; //创建搜索条件的类 HouseSearchOptions searchOpt = new HouseSearchOptions(); searchOpt.CityId = cityId; //当前页的页码 searchOpt.CurrentIndex = 1; //解析月租部分 int?startMonthRent; int?endMonthRent; //ref/out ParseMonthRent(monthRent, out startMonthRent, out endMonthRent); searchOpt.EndMonthRent = endMonthRent; searchOpt.StartMonthRent = startMonthRent; //搜索关键字 searchOpt.Keywords = keyWords; //排序规则 switch (orderByType) { case "MonthRentAsc": searchOpt.OrderByType = HouseSearchOrderByType.MonthRentAsc; break; case "MonthRentDesc": searchOpt.OrderByType = HouseSearchOrderByType.MonthRentDesc; break; case "AreaAsc": searchOpt.OrderByType = HouseSearchOrderByType.AreaAsc; break; case "AreaDesc": searchOpt.OrderByType = HouseSearchOrderByType.AreaDesc; break; } //每页的条数 searchOpt.PageSize = 10; //区域的id searchOpt.RegionId = regionId; //房屋的类型(合租,整租) searchOpt.TypeId = typeId; //开始搜索 var searchResult = houseService.Search(searchOpt); model.houses = searchResult.result; //当前用户城市Id return(View(model)); }