我在MVC創建銀行應用程序由銀行銀行和負載錶行5避免重複上的ViewPage的結果MVC
負載表,
但我想不出做到這一點酷似上圖中,
這就是我得到,它有10個表,而不是僅僅2個表
這是上述觀點CSHTML代碼
@model IEnumerable<albaraka.Models.ProductApprovals>
@{
ViewBag.Title = "Product_Approvals";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>sadfasf</h2>
<h2>Product Approvals</h2>
@using (Html.BeginForm("Index", "Student", FormMethod.Get))
{
<div> Filter by : Date @Html.TextBox("SearchString", ViewBag.CurrentFilter as string) Filter by : Country @Html.TextBox("SearchString", ViewBag.CurrentFilter as string) <input type="submit" value="Search" /> </div>
}
@foreach (var item in Model)
{
@Html.DisplayNameFor(model => model.SubsidaryName); <p   /> @Html.DisplayFor(modelItem => item.SubsidaryName);
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.ProductNameEn)
</th>
<th>
@Html.DisplayNameFor(model => model.ProdcutNameAr)
</th>
<th>
@Html.DisplayNameFor(model => model.CurrentStatus)
</th>
<th>
Actions
</th>
</tr>
@foreach (var inside in Model)
{
if (inside.Subsidary_ID == item.Subsidary_ID)
{
<tr>
<td>
@Html.DisplayFor(modelItem => inside.ProductNameEn)
</td>
<td>
@Html.DisplayFor(modelItem => inside.ProdcutNameAr)
</td>
<td>
@Html.DisplayFor(modelItem => inside.CurrentStatus)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
</td>
</tr>
}
}
</table>
}
這是Model類
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace albaraka.Models
{
public class ProductApprovals
{
public DateTime SearchDate { get; set; }
public string Country { get; set; }
public string Product_ID { get; set; }
public string Subsidary_ID { get; set; }
public string SubsidaryName { get; set; }
public string ProductNameEn { get; set; }
public string ProdcutNameAr { get; set; }
public string CurrentStatus { get; set; }
}
}
這是Controller類
public ActionResult Product_Approvals()
{
var productApproveResult =(from p in db.AB_Product
join s in db.AB_Subsidary on p.Subsidary_ID equals s.SubsidaryID
select new ProductApprovals
{
Product_ID = p.ProductID,
Subsidary_ID = s.SubsidaryID,
SubsidaryName = s.SubsidaryNameEn,
ProductNameEn = p.ProductTitleEn,
ProdcutNameAr = p.ProductTitleAr,
CurrentStatus = p.Status
}).ToList();
return View(productApproveResult);
}
如何停止這種重複,appricate如果能請參閱頁面
你必須收集2'foreach'渲染模型中的所有項目。使用具有銀行屬性的視圖模型,幷包含與後者相關的數據集合。然後你的樣子是'foreach(模型中的var bank){//銀行名稱等foreach(銀行中的var詳細信息){//銀行記錄}}' –
我確實像你說的那樣'foreach語句不能操作類型的變量'albaraka.Models.ProductApprovals',因爲'albaraka.Models.ProductApprovals'沒有包含'GetEnumerator''的公開定義,所以我應該怎麼做 – kez
您需要展示您的當前模型(以便我們可以修復它們) –