我有一个页面,该页面根据传递给该页面的用户显示过滤表。我还想在页面顶部显示用户的信息,但这来自不同的表(来自 Account 模型)。在我的其他控制器/视图中工作时,有没有办法可以访问该表中的字段?
这是我的代码:
@{
ViewBag.Title = "User Profile";
}
@model IEnumerable<FTv2.Models.Trade>
@{
ViewBag.Title = "Active Trades";
ViewBag.ImgUrl = ViewBag.Name + ".png";
}
<h2>@ViewBag.User's Profile:</h2>
<p>
// This is where I would like to put the User info.
</p>
<h2>Active Trades:</h2>
<p>
</p>
<table>
<tr>
<th>
</th>
<th>
@Html.DisplayNameFor(model => model.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.Price)
</th>
<th>
@Html.DisplayNameFor(model => model.User)
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
if (item.User == ViewBag.User)
{
<tr>
<td>
@{ViewBag.ImgUrl = @item.Name + ".png";}
<a href="/Images/@ViewBag.ImgUrl"><img src="/Images/@ViewBag.ImgUrl" HEIGHT="66" WIDTH="50" ></a>
</td>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Price) TE
</td>
<td>
<a href="/ActiveTrades/@item.User">@Html.DisplayFor(modelItem => item.User)</a>
</td>
@{if (ViewBag.User == User.Identity.Name){
<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>