0
我試圖顯示同一個表(組列值)的不同結果,每次我在同一視圖中單擊一個選項卡時。MVC表在同一視圖上多次過濾查看
澄清請查看:
視圖代碼:
@model IEnumerable<RapidScan_v2.Models.lu_performance_reason>
@{
ViewBag.Title = "Index";
}
<h2>Playbook</h2>
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active"> <a href="#Consumables" aria-controls="Consumables" role="tab" data-toggle="tab">Consumables</a></li>
<li role="presentation"> <a href="#DocuCareLabour" aria-controls="DocuCareLabour" role="tab" data-toggle="tab">DocuCare Labour</a></li>
<li role="presentation"> <a href="#Parts" aria-controls="Parts" role="tab" data-toggle="tab">Parts</a></li>
<li role="presentation"> <a href="#PrintProductionLabour" aria-controls="PrintProductionLabour" role="tab" data-toggle="tab">Print Production Labour</a></li>
<li role="presentation"> <a href="#Revenue" aria-controls="Revenue" role="tab" data-toggle="tab">Revenue</a></li>
<li role="presentation"> <a href="#TechnicalService" aria-controls="TechnicalService" role="tab" data-toggle="tab">Technical Service</a></li>
<li role="presentation"> <a href="#Depreciation" aria-controls="Depreciation" role="tab" data-toggle="tab">Depreciation</a></li>
<li role="presentation"> <a href="#OtherCosts" aria-controls="OtherCosts" role="tab" data-toggle="tab">Other Costs</a></li>
</ul>
@section LeftMenu{
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="Consumables">
@using (Html.BeginForm())
{
<p>
Consumables: @Html.Hidden("search1","Consumables")
<input type="submit" value="Search" />
</p>
}
<table class="table">
<tr>
<th>
Perf Reason
</th>
<th>
Action
</th>
<th>
Action Description
</th>
<th>
Info EU
</th>
<th>
Info US
</th>
<th>
Helper Team
</th>
<th>
Target
</th>
<th>
Group
</th>
<th>
Cost Reason
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.dsc_performance_reason)
</td>
<td>
@Html.DisplayFor(modelItem => item.dsc_investigation_actions)
</td>
<td>
@Html.DisplayFor(modelItem => item.dsc_actions)
</td>
<td>
@Html.DisplayFor(modelItem => item.dsc_additional_info_europe)
</td>
<td>
@Html.DisplayFor(modelItem => item.dsc_additional_info_usa)
</td>
<td>
@Html.DisplayFor(modelItem => item.lu_action_helper.dsc_action_helper)
</td>
<td>
@Html.DisplayFor(modelItem => item.lu_action_target.dsc_action_target)
</td>
<td>
@Html.DisplayFor(modelItem => item.lu_cost_bucket.dsc_cost_bucket)
</td>
<td>
@Html.DisplayFor(modelItem => item.lu_cost_reason.dsc_cost_reason)
</td>
<td>
@Html.ActionLink("Add to Contract", "Create", "fact_contract_actions_mn", new { id = item.cod_performance_reason }, null)
</td>
</tr>
}
</table>
</div>
<div role="tabpanel" class="tab-pane" id="DocuCareLabour">
<p>DocuCare Labour</p>
</div>
<div role="tabpanel" class="tab-pane" id="Parts">
<p>Parts</p>
</div>
<div role="tabpanel" class="tab-pane" id="PrintProductionLabour">
<p>Print Production Labour</p>
</div>
<div role="tabpanel" class="tab-pane" id="Revenue">
<p>Revenue</p>
</div>
<div role="tabpanel" class="tab-pane" id="TechnicalService">
<p>Technical Service</p>
</div>
<div role="tabpanel" class="tab-pane" id="Depreciation">
<p>Depreciation</p>
</div>
<div role="tabpanel" class="tab-pane" id="OtherCosts">
<p>Other Costs</p>
</div>
</div>
}
我將通過所有的 「標籤」 用更少的列複製的表,這是解決之後。我在控制器上添加了搜索功能,但我相信有更好的方法,因爲這隻會在輸入後返回我想要的內容。
這裏的控制器代碼:
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using RapidScan_v2.Models;
namespace RapidScan_v2.Controllers
{
public class lu_performance_reasonController : Controller
{
private RapidScanEntities2 db = new RapidScanEntities2();
// GET: lu_performance_reason
public ActionResult Index(string search1)
{
var lu_performance_reason = from lpr in db.lu_performance_reason.Include(l => l.lu_action_helper).Include(l => l.lu_action_target).Include(l => l.lu_cost_bucket).Include(l => l.lu_cost_reason)
select lpr;
if (!string.IsNullOrEmpty(search1))
{
lu_performance_reason = lu_performance_reason.Where(lpr => lpr.lu_cost_bucket.dsc_cost_bucket.Contains(search1));
}
return View(lu_performance_reason.ToList());
}
我相信過濾是答案,但我堅持的時刻。