高级搜索没有在MVC 4中下载城市

时间:2014-09-13 05:30:28

标签: asp.net asp.net-mvc asp.net-mvc-3 asp.net-mvc-4

 @using (Html.BeginForm("Search", "Home", FormMethod.Post))
    {


        <figure class="span3 pull-left left_background">
            <div class="span4 pull-left">
                <div class="left_container pull-left">

                    <div class="tab">
                        @Html.RadioButton("Type", "Sale", new { onchange = "this.form.submit();" }) Buy
                @Html.RadioButton("Type", "Rent", new { onchange = "this.form.submit();" }) Rent
                    </div>

                    <span class="search_headings">City:</span><br>

                    @Html.DropDownList("City", null, "Select City", new { @class = "span11", Id = "CityS" })

                    @Html.DropDownList("Locality", null, "Select Locality", new { @class = "span11", Id = "LocalityS" })


                        
                                                      热门过滤器                 
                                                              

                    <span class="search_headings">Type of Property:</span><br>

                    <select data-placeholder="Choose a Type of Property..." id="ddlproperty" class="chosen-select" name="property" multiple style="width: 350px;" tabindex="4">
                        <option value=""></option>
                        <option value="Apartment">Apartment</option>
                        <option value="IndividualHouse">Individual House</option>
                        <option value="RowHouse">Row House</option>
                        <option value="Villa">Villa</option>
                        <option value="Plot">Plot</option>
                        <option value="BuilderFloor">Builder Floor</option>
                        <option value="Penthouse">Penthouse</option>
                        <option value="FormHouse">Form House</option>
                        <option value="ServiceApartment">Service Apartment</option>
                        <option value="StudioApartment">Studio Apartment</option>
                    </select>


                    @foreach (var l in (SelectList)ViewBag.typeproperty)
                    {
                        <input type="checkbox" class="required"  name="property" value="@l.Value" id="@l.Value" @l.Selected ? "checked='checked';" : @String.Empty /> 
                        <label for="l@(l.Value)">@l.Text</label>
                    }
                    <br>
                    <br>
                    <span class="search_headings">Budget:</span><br>
                    <span class="span11 pull-left">
                        @Html.TextBox("min", null, new { @class = "input-mini", @placeholder = "Min", @id = "min" })
                        to
                        @Html.TextBox("max", null, new { @class = "input-mini", @placeholder = "Max", @id = "max" })

                        <br>
                        <br>
                    </span>
                    <span class="search_headings">Bed Rooms:</span><br>
                    @Html.DropDownList("Bed", (IEnumerable<SelectListItem>)ViewBag.Rooms, "Any", new { @class = "span11", @id = "min" })

                    <br>
                    <br>
                </div>
            </div>
            <div class="span4 pull-left refine_heading show">More Filters</div>
            <br />
            <div class="span4 pull-left show_content">
                <div class="left_container pull-left">
                    <br />
                    <span class="search_headings">Bath Rooms:</span><br>
                    @Html.DropDownList("Bath", (IEnumerable<SelectListItem>)ViewBag.bath, new { @class = "span11", @id = "Bath" })

                    <br>
                    <br>


                    <span class="search_headings">Direction Facing:</span>
                    @Html.DropDownList("dir", (IEnumerable<SelectListItem>)ViewBag.dir, new { @class = "span11", @id = "dir" })

                    <br>
                    <span class="search_headings">Flooring :</span>
                    @Html.DropDownList("fr", (IEnumerable<SelectListItem>)ViewBag.floor, new { @class = "span11", @id = "fr" })

                    <br>
                    <span class="search_headings">Water:</span>
                    @Html.DropDownList("wt", (IEnumerable<SelectListItem>)ViewBag.water, new { @class = "span11", @id = "wt" })
                    <br>
                    <br>
                </div>
            </div>
            <div class="span4 pull-left refine_heading">Upcoming Event:</div>
            <span class="span4 pull-left hr"></span>
            <div class="span4 pull-left padding-left"><a href="#">
                <img src="~/Images/img.jpg" alt=""></a></div>
            <br>
        </figure>

        <br />

        <br />


        @Html.Partial("_PropertyFilters", Model)

        <figure class="span5 pull-left bodyleft_container_inner">

            <div id="table">
            </div>
        </figure> 


    }
</section>

$('select[id="CityS"]').change(function () {
         selectedvalue = $(this).val();

         var subItems = "";
         $("#table").empty();
         $.getJSON('@Url.Action("testcata", "home")' + '?property=' + "@(Session["pro"])" + "&Type=" + "@(Session["typ"])" + "&city=" + selectedvalue + "&loc=" + "@(Session["loc"])" + "&Bed=" + "@(Session["Bed"])" + "&min=" + "@(Session["min"])" + "&max=" + "@(Session["max"])" + "&Bath=" + "@(Session["Bath"])" + "&tw=" + "@(Session["tw"])" + "&fw=" + "@(Session["fw"])" + "&dir=" + "@(Session["dr"])" + "&fr=" + "@(Session["fr"])" + "&wt=" + "@(Session["wt"])",
                    function (data) {
                        console.log(data);
                        if (data != null) {
                            $.each(data, function (index, item) {
                                console.log(item.Roomdetails);
                                var len = data.length;
                                var txt = "";
                                if (len > 0) {

                                    for (var i = 0; i < len; i++) {

                                        if (data[i].Roomdetails && data[i].Photo && data[i].SaleorRent && data[i].Locality && data[i].City && data[i].propertytype && data[i].date && data[i].ProjectName && data[i].Monthlyrent) {
                                            var date = new Date(parseInt(data[i].date.substr(6)));

                                            // txt += "<tr><td>" + data[i].Roomdetails + "for" + data[i].SaleorRent + "in" + data[i].Locality + data[i].City + "</td></tr><tr><td> Property Type: <td><td>" + data[i].propertytype + "</td></tr><tr><td>" + data[i].Monthlyrent + "</td></tr><tr><td> Builder: </td><td>" + data[i].ProjectName + "</td><td>" + "</td></tr>";
                                            //txt += "<tr><td> <table><tr><td>" + "></td><td><table> <tr> <td>" + data[i].Roomdetails + "for" + data[i].SaleorRent + "in" + data[i].Locality + data[i].City + "</td></tr> <tr> <td>Builder:</td><td>" + data[i].ProjectName + "</td> </tr><tr><td>Property Type:</td><td>" + data[i].propertytype + "</td> </tr><tr> <td>Unit Type:</td><td>" + data[i].Roomdetails + "</td> </tr> <tr> <td>Posted On :</td><td>" + data[i].date + "</td></tr> </table></td><td><table><tr><td>" + data[i].Monthlyrent + "</td></tr> <tr><td></td></tr> <tr><td></td></tr></table></td> </tr></table></td></tr>";
                                            txt += '<div class="span5  pull-left subcategory_section"><div class="span4 pull-left">' + '</div> <div class="span12 pull-left"><div class="span12 pull-left h2">' + data[i].Roomdetails + "for" + data[i].SaleorRent + "in" + data[i].Locality + "," + data[i].City + '</div><div class="span12 pull-left padding_left"><span class="span1 pull-left buldier_content">Builder:</span> <a href="#" class="price_content">' + data[i].ProjectName + '</a></div> <div class="span12 pull-left padding_left"><span class="span1 pull-left buldier_content">Property Type:</span> <span class="apartments_content">' + data[i].propertytype + '</span></div> <div class="span12 pull-left padding_left"><span class="span1 pull-left buldier_content">Unit Type:</span> <span class="apartments_content">' + data[i].Roomdetails + '</span></div> <div class="span12 pull-left padding_left"><span class="span1 pull-left buldier_content">Posted On :</span> <span class="apartments_content">' + date + '</span></div></div><div class="span4 pull-left"> <span class="span4 pull-left text_align_right">Rs. ' + data[i].Monthlyrent + '</span><br><span class="span4 pull-left buldier_content align_right">' + "Sq. Ft." + '</span><br><span class="span4 pull-left"></span><br><br /><br /><span class="span4 pull-left align_right">' + ' <a href="SearchDetails/' + data[i].Id + '" class="more_content">More Details</a></span><br></div></div> ';
                                        }
                                    }
                                    if (txt != "") {
                                        $("#table").append(txt).removeClass("hidden");
                                    }
                                }
                                return false;
                            }

                            );

                        }
                        else {
                        }
                    });
     });

上面发布的查询位于高级搜索页面,我们可以在该页面中搜索特定城市的媒体资源。只需更改城市,搜索过程就会开始。以下是根据用户搜索从数据库中提取数据的控制器。

 public ActionResult testcata(string Type, int? city,int? loc,string property,string Bed,int? Bath, int? tw, int? fw, int? dir, int? fr, int? wt, int? min, int? max)
    {

        NullData(property, Bed, tw,fw,dir,fr,wt);

        var model = (from m in db.Properties
                     join p in db.PropertyType on m.Typeofproperty equals p.PropTypeId
                     join r in db.BedRoom on m.Roomdetails equals r.BedRoomId
                     join c in db.Cities on m.CityId equals c.CityId
                     join l in db.Areas on m.Locality_Id equals l.Locality_Id
                     join b in db.BathRoom on m.Bathrooms equals b.BathRoomId
                     join f in db.Flooring on m.Flooring equals f.FloorId
                     join w in db.WaterSupplies on m.water equals w.WaterId
                     join fur in db.Furnish on m.Furnished equals fur.FurnishId
                     join dire in db.DirectionFace on m.DirectionFacing equals dire.DirectionId

                     join tp in db.Parking on m.Twowheelerparking equals tp.ParkId
                     join fp in db.Parking on m.Fourwheelerparking equals fp.ParkId

                     select new { m.Id, m.ProjectName, m.Photo, w.WaterId, m.Roomdetails, m.SaleorRent, m.CreatedDate, m.BuiltUpArea, m.Amenities, l.Locality, l.Locality_Id, c.City, c.CityId, m.Monthlyrent, m.Propertyvalue, p.PropertyTypes, p.PropTypeId, r.BedRoom, r.BedRoomId, b.BathRoomId, tp.ParkId, m.Fourwheelerparking, f.FloorId, dire.DirectionId })
                      .Select(m => new propertylist
                      {
                          Id = m.Id,
                          ProjectName = m.ProjectName,
                          Roomdetails = m.BedRoom,
                          RoomdetailsId = m.BedRoomId,
                          SaleorRent = m.SaleorRent,
                          BuildupArea = m.BuiltUpArea,
                          Locality = m.Locality,
                          LocalityId = m.Locality_Id,
                          City = m.City,
                          CityId = m.CityId,
                          Photo = m.Photo,
                          Monthlyrent = m.Monthlyrent,
                          Propertyvalue = m.Propertyvalue,
                          propertytype = m.PropertyTypes,
                          propertytypeId = m.PropTypeId,
                          TpId = m.ParkId,
                          FpId = m.Fourwheelerparking,
                          DirId = m.DirectionId,
                          FloorId = m.FloorId,
                          WaterId = m.WaterId,
                          Bathid = m.BathRoomId,
                          date = m.CreatedDate
                      }).ToList();
        if (!string.IsNullOrWhiteSpace(Type))
        {
            Session["typ"] = Type;
            model = model.Where(m => m.SaleorRent == Type).ToList();
        }
        else if (Session["typ"] != null && Session["typ"] != "")
        {
            model = model.Where(m => m.SaleorRent == Session["typ"]).ToList();
        }
        if (city != null)
        {
            Session["cit"] = city;
            model = model.Where(m => m.CityId == city).ToList();
        }
        else if (Session["cit"] != null && Session["cit"] != "")
        {
            model = model.Where(m => m.CityId == Convert.ToInt32(Session["cit"])).ToList();
        }
        if (loc != null)
        {
            Session["loc"] = loc;
            model = model.Where(m => m.LocalityId == Convert.ToInt32(Session["loc"])).ToList();
        }
        else if (Session["loc"] != null && Session["loc"] != "")
        {
            model = model.Where(m => m.LocalityId == Convert.ToInt32(Session["loc"])).ToList();
        }

        if (property != null && property != "" && property != "null")
        {
            Session["pro"] = property;
            model = model.Where(m => property.Contains(m.propertytype)).ToList();
        }
        else if (Session["pro"] != null && Session["pro"] != "" && property != "null")
        {
            Session["pro"] = Session["pro"];
            model = model.Where(m => Session["pro"].ToString().Contains(m.propertytype)).ToList();
        }
        if (Bed != null && Bed != "" && Bed != "null")
        {
            Session["Bed"] = Bed;
            model = model.Where(m => Bed.ToString().Contains(m.RoomdetailsId.ToString())).ToList();
        }
        else if (Session["Bed"] != null && Session["Bed"] != "" && Bed != "null")
        {
            model = model.Where(m => Session["Bed"].ToString().Contains(m.RoomdetailsId.ToString())).ToList();

        }

        if (Bath != null)
        {
            Session["Bath"] = Bath;
            model = model.Where(m => m.Bathid == Bath).ToList();
        }
        else if (Session["Bath"] != null && Session["Bath"] != "")
        {
            model = model.Where(m => m.Bathid ==Convert.ToInt32( Session["Bath"])).ToList();
        }
        if (min != null && max != null)
        {
            Session["min"]=min;
            Session["max"]=max;
            if (Type == "Rent")
            {

                model = model.Where(m => m.Monthlyrent >= min && m.Monthlyrent <= max).ToList();
            }
            if (Type == "Sale")
            {

                model = model.Where(m => m.Propertyvalue >= min && m.Propertyvalue <= max).ToList();
            }
        }
        else if (Session["min"] != null && Session["max"] != null)
        {
            if (Type == "Rent")
            {

                model = model.Where(m => m.Monthlyrent >= Convert.ToInt64(Session["min"]) && m.Monthlyrent <= Convert.ToInt64(Session["max"])).ToList();
            }
            if (Type == "Sale")
            {

                model = model.Where(m => m.Propertyvalue >= Convert.ToInt64(Session["min"]) && m.Propertyvalue <= Convert.ToInt64(Session["max"])).ToList();
            }
        }
        if (tw != null&&tw!=1)
        {
            Session["tw"] = tw;
            model = model.Where(m => m.TpId == tw).ToList();
        }
        else if (Session["tw"] != null && Session["tw"] != "")
        {
            model = model.Where(m => m.TpId ==Convert.ToInt32 (Session["tw"])).ToList();
        }
        if (fw != null && fw != 1)
        {
            Session["fw"]=fw;
            model = model.Where(m => m.FpId == fw).ToList();
        }
        else if (Session["fw"] != null && Session["fw"] != "")
        {
            model = model.Where(m => m.FpId == Convert.ToInt32(Session["fw"])).ToList();
        }
        if (dir != null && dir != 1)
        {
            Session["dir"]=dir;
            model = model.Where(m => m.DirId == dir).ToList();
        }
        else if (Session["dir"] != null && Session["dir"] != "")
        {
            model = model.Where(m => m.DirId == Convert.ToInt32(Session["dir"])).ToList();
        }
        if (fr != null && fr != 1)
        {
            Session["fr"]=fr;
            model = model.Where(m => m.FloorId == fr).ToList();
        }
        else if (Session["fr"] != null && Session["fr"] != "")
        {
            model = model.Where(m => m.FloorId == Convert.ToInt32(Session["fr"])).ToList();
        }
        if (wt != null && wt != 1)
        {
            Session["wt"] = wt;
            model = model.Where(m => m.WaterId == wt).ToList();
        }
        else if (Session["wt"] != null&&Session["wt"] !="")
        {
            model = model.Where(m => m.WaterId == Convert.ToInt32(Session["wt"])).ToList();
        }

        return Json(model, JsonRequestBehavior.AllowGet);
    }

0 个答案:

没有答案