我有两个数据库。一个数据库包含产品及其详细信息。每个产品都有特定的库存编号(例如AG1000)。第二个数据库包含有关员工输入的每种产品的注释(例如,更新日期,注释,以及包含该产品的库存编号的列)。
对于底部的“产品详细信息”页面,我想填充一个表格,该表格显示第二个数据库中包含所示产品详细信息的库存编号的所有条目。
我已成功将局部视图以及占位符表传递给该视图。但是不幸的是,我终生无法将库存编号传递给部分股票,也无法获得控制器/部分股票来将数据库2中的所有行显示到表中。
查看:
INSERT INTO CUSTOMER_ORDER_DATA(email, order_id, orders)
SELECT C.Email,
C.orderid,
'{"email":"' + CASE WHEN @Email IS NULL THEN '' ELSE
@Email END + '"'
+ ',"eventName": "ChristmasSale", "dataFields": {'
+ '"orderId":' + CAST(CASE WHEN @OrderId IS NULL THEN 0 ELSE
@OrderId END AS varchar)
+ ',"paymentType":"' + CASE WHEN @PaymentType IS NULL THEN
'' ELSE @PaymentType END + '"'
+ ',"products": ' +
('[' + STUFF((
SELECT
',{"orderProductID":' + CAST(orderProductID AS varchar)
+ ',"productType":"' + ProductType + '"'
+ ',"productName":"' + ProductName + '"'
+ ',"categoryName":"' + CategoryName + '"'
+'}'
FROM ORDERS AS O
WHERE O.orderid = C.orderid
FOR XML PATH(''),TYPE).value('.', 'varchar(max)'), 1, 1, '') + ']')
FROM CUSTOMER AS C
_Partial:
OFFSET
控制器:
@model IdentitySample.Models.InventoryViewModels
@{
ViewBag.Title = "Details";
string StockNumber = Model.StockNumber;
}
<p class="text-right align-top">@Html.ActionLink("Back to List", "Index")</p>
<div class="container">
<hr />
<div class="card">
<div class="card-header"><h2 class="text-center">@Html.DisplayFor(model => model.Year) @Html.DisplayFor(model => model.Make) @Html.DisplayFor(model => model.Model) @Html.DisplayFor(model => model.Trim)</h2></div>
<div class="card-body">
<div class="row">
<div class="col"><img style="width:100%;" src="@Html.DisplayFor(model => model.PhotoUrl)" /></div>
<div class="col">
<div class="card">
<div class="card-header"> <h5>Vehicle Details</h5></div>
<div class="card-body">
<table class="table table-light table-hover table-striped thead-dark">
<tbody>
<tr>
<th>@Html.DisplayNameFor(model => model.StockNumber)</th>
<td>@Html.DisplayFor(model => model.StockNumber)</td>
</tr>
<tr>
<th>@Html.DisplayNameFor(model => model.Year)</th>
<td>@Html.DisplayFor(model => model.Year)</td>
</tr>
<tr>
<th>@Html.DisplayNameFor(model => model.Make)</th>
<td>@Html.DisplayFor(model => model.Make)</td>
</tr>
<tr>
<th>@Html.DisplayNameFor(model => model.Model)</th>
<td>@Html.DisplayFor(model => model.Model)</td>
</tr>
<tr>
<th>@Html.DisplayNameFor(model => model.Trim)</th>
<td>@Html.DisplayFor(model => model.Trim)</td>
</tr>
<tr>
<th>@Html.DisplayNameFor(model => model.Odometer)</th>
<td>@Html.DisplayFor(model => model.Odometer)</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<br />
<div class="row">
<div class="col-12">
<div class="card" style="width: 100%;">
<div class="card-header align-middle"><h5>Vehicle Log<a href="#" class="fa fa-2x fa-plus-square float-right"></a></h5></div>
<div class="card-body">
@Html.Partial("_ViewActions", new List<IdentitySample.Models.InventoryActionsModels>())
</div>
</div>
</div>
</div>
</div>
</div>
</div>
答案 0 :(得分:0)
猜想您应该为库存明细创建一个复合视图模型,然后将其传递给您的视图
public class InventoryDetailsViewModel
{
public InventoryModel Inventory { get; set; }
public ICollection<InventoryActionsModels> Actions { get; set; }
}
控制器
public async Task<ActionResult> GetInventoryDetails(string stockNumber)
{
var viewModel = new InventoryDetailsViewModel
{
Inventory = await GetInventoryById(stockNumber),
Actions = await GetInventoryActions(stockNumber)
};
return View(viewModel);
}
其中GetInventoryById和GetInventoryActions是从数据库获取信息的方法
然后在视图中
@model IdentitySample.Models.InventoryDetailsViewModel
@Html.Partial("_ViewInventory", Model.Inventory)
@Html.Partial("_ViewActions", Model.Actions)