У меня есть две базы данных.Одна база данных содержит продукты, а также их детали.Каждый продукт имеет определенный номер запаса (например, AG1000).Вторая база данных содержит комментарии относительно каждого продукта, введенного сотрудниками (например, Дата обновления, Комментарии, а также столбец, содержащий номер запаса продукта).
Для страницы сведений о продукте внизу, я хочудля заполнения таблицы, отображающей все записи во второй базе данных, содержащие номер запаса показанных сведений о продукте.
Я успешно передал частичное представление как представлению, так и таблице заполнителей.Но, к сожалению, я не могу всю жизнь передать номер запаса частичному и заставить контроллер / частичку отобразить в таблице все строки из базы данных 2.
VIEW:
@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>
_Partial:
@model IEnumerable<IdentitySample.Models.InventoryActionsModels>
<h5>Test Inventory Action View: @ViewBag.StockNumber</h5>
<table class="table table-light table-hover table-striped thead-dark">
<tr>
<th>
@Html.DisplayNameFor(model => model.StockNumber)
</th>
<th>
@Html.DisplayNameFor(model => model.TouchType)
</th>
<th>
@Html.DisplayNameFor(model => model.TouchedBy)
</th>
<th>
@Html.DisplayNameFor(model => model.TouchDate)
</th>
<th>
@Html.DisplayNameFor(model => model.TouchComments)
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.StockNumber)
</td>
<td>
@Html.DisplayFor(modelItem => item.TouchType)
</td>
<td>
@Html.DisplayFor(modelItem => item.TouchedBy)
</td>
<td>
@Html.DisplayFor(modelItem => item.TouchDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.TouchComments)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.Id }) |
@Html.ActionLink("Details", "Details", new { id = item.Id }) |
@Html.ActionLink("Delete", "Delete", new { id = item.Id })
</td>
</tr>
}
</table>
Контроллер:
// GET: InventoryActions
public ActionResult Index()
{
// ViewBag.StockNumber();
string vehicleId = StockNumber;
var vehicle = db.InventoryActionsModels.GroupBy(i => i.StockNumber)
.Select(g => new InventoryActionsModels()
{
StockNumber = vehicleId,
Id = g.Max(row => row.Id)
}).ToList();
return View(db.InventoryActionsModels.ToListAsync());
}