我有一个与模型关联的视图:ICS_Orders。此视图用于用户打印带有记录的表单。
用户已请求在打印视图上显示一个新字段。该字段不是ICS_Orders模型的一部分,而是ICS_Supplies。我似乎找不到关于如何使该字段显示在视图上的任何信息-来自其他模型。
查看代码:
@model IEnumerable<ICS20web.Models.ICS_Orders>
<table class="table">
<tr>
<th>PO / Requisition Number</th>
<th>Units Ordered</th>
<th>Supply Name</th>
<th>**New Field from Different Model Here** </th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>@Html.DisplayFor(modelItem => item.RequisitionNumber)</td>
<td>@Html.DisplayFor(modelItem => item.Unitsordered)</td>
<td>@Html.DisplayFor(modelItem => item.Supply)</td>
<td>**New Field Display Resuls** <td>
</tr>
}
</table>
如您所见,该视图适用于
@model IEnumerable<ICS20web.Models.ICS_Orders>
新的请求字段(Old_ItemID)用于:
@model IEnumerable<ICS20web.Models.ICS_Supplies>
(WHERE item.Supply(来自当前模型:ICS_Orders)= item.Description(新模型:ICS_Supplies)
有没有办法做到这一点?还是我必须一直追溯到我的数据库和新模型中创建视图?
编辑:
下面是我的ICS_Orders模型
public class ICS_Orders
{
[Key]
public int? LineID { get; set; }
[Required]
public string RequisitionNumber { get; set; }
public int SuppliesID { get; set; }
[Required]
public int Unitsordered { get; set; }
public string Supply { get; set; }
public Nullable<int> UnitsDelivered { get; set; }
}
如何添加属性以容纳ICS_Supplies字段“ Old_ITemID”?我尝试了以下操作,但没有用。
public virtual DbSet<ICS_Supplies> ICS_Order { get; set; }
public string Old_ItemID { get; set; }
根据建议,我需要在控制器中做什么以“设置此值”。