我在www.example.com核心mvc中使用sql查询创建从数据库中获取数据的表单asp.net。现在我想使用多个字段搜索数据,如价格、面积、面积单位。我是c#新手,请帮助我搜索数据并显示。数据显示在其他div中。在该div中,我使用foreachloop制作卡片并从数据库中获取数据。我的视图:
@model IEnumerable<eHouse.Models.RentModel>
<form>
<div class="wrap">
<div class="search">
<input type="text" class="searchTerm" style="width: 700px; color:#000000; text-align: left;" placeholder="Search Houses" onclick="filterfunction()">
<button type="submit" class="searchButton" >
<i class="fa fa-search"></i>
</button>
</div>
<div id="filter">
<select>
<option value="Kanal">Kanal</option>
<option value="Marla">Marla</option>
<option value="Square Feet">Square Feet</option>
<option value="Square Meter">Square Meter</option>
<option value="Square Yards">Square Yards</option>
</select>
<input type="text" placeholder="area" />
<input type="text" placeholder="price" />
</div>
</div>
</form>
<div class="property_information" >
@foreach (var item in Model)
{
<div class="home-info">
<span id="houseid">
</span>
<a href="#" class="home-images">
<img src="@item.pic1" />
</a>
<div class="home-data">
<div class="home-name">
<p>@item.tittle</p>
</div>
<div class="price">
<p>@item.price</p>
</div>
<div class="features">
<span>
@item.bedroom
</span>
<span>
@item.bathroom
</span>
<span>
2
</span>
</div>
<div class="desc">
@item.descrip
</div>
<div class="contact-save">
<a href="#" class="phone_number" id="favorite" onclick="Fav(this)" data-id="@item.id" >
<i class="fas fa-heart" style=" color: white;"></i>
</a>
<div class="popup" onclick="myFunction()">
<a href="tel:+928754756478" class="phone_number" onclick="call()">
</a>
</div>
<div class="popupmsg" onclick="myFunctionmsg()">
<a href="#" class="phone_number open_message" onclick="msg()">
</a>
</div>
<a href="#" class="phone_number" onclick="del(this)" data-id="@item.id">
<i class="fas fa-trash-alt" style=" color: white;"></i>
</a>
</div>
</div>
</div>
}
</div>
我的控制器:
public IActionResult Rent(int PageNumber = 1)
{
var data = rdb.GetDataHouse();
var datas = rdb.GetDataHouse();
ViewBag.Data = datas.ToList().Take(6);
ViewBag.Totalpages = Math.Ceiling(data.Count()/6.0);
data = data.Skip((PageNumber - 1) * 6).Take(6).ToList();
return View(data);
}
1条答案
按热度按时间q3aa05251#
通过表单中的输入提交传递过滤器数据。您将需要新的
viewModel
和您的data
、用于post的input
以及filterList
。您需要类似于以下内容的内容:你还需要一些其他的东西,希望你能处理好