我正在嘗試通過單擊選項卡來過濾表中的資料,但我不知道如何在視圖中系結資料。
視圖代碼(選項卡):
<ul class="nav nav-tabs" role="tablist">
<li class="nav-item" role="presentation">
<a class="nav-link active" data-bs-toggle="tab" role="tab" aasp-action="">North</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" data-bs-toggle="tab" role="tab" tabindex="-1">South</a>
</li>
</ul>
查看代碼(資料表):
<table class="table">
<thead>
<tr>
<th>Region Name</th>
<th>Country Name</th>
</tr>
</thead>
<tbody>
@foreach(var data in @Model.Where(data => data.Region_Name.Trim() == REGION_NAME_BASED_ON_TAB).ToList())
{
<tr>
<td>@data.Region_Name</td>
<td>@data.Country_Name</td>
</tr>
}
</tbody>
</table>
據我所知,也許這可以通過使用控制器來解決,這個語法是什么樣的?
任何的意見都將會有幫助。
謝謝!
uj5u.com熱心網友回復:
假設您正在使用 Entity Framwework
public IActionResult Index(string? REGION_NAME_BASED_ON_TAB)
{
var model = from s in db.<YourTableName>
select s;
if (!String.IsNullOrEmpty(REGION_NAME_BASED_ON_TAB))
{
model = model.Where(a => a.Region_Name.ToLower().Contains(REGION_NAME_BASED_ON_TAB.ToLower()));
}
return View(model.ToList());
}
在您的清單開始之前添加這個
<li class="nav-item" role="presentation">
<a class="nav-link active" data-bs-toggle="tab" role="tab" href="@Url.Action("Index","YoutController",new{REGION_NAME_BASED_ON_TAB= "North"})>North</a>
</li>
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/508221.html
標籤:asp.net-mvc 筛选 html表
上一篇:Blazorwebassembly發布到本地檔案夾失敗
下一篇:真偽值不變