我已经拉出了活动目录中的用户列表,这些活动目录具有活动报告给当前用户,并已成功在MVC 5中的Web视图表中显示列表。如何在MVC 5 Web视图中使用Model变量?
但是,当遇到问题时我尝试在Web视图中的表格上方打印当前用户的名称。
有谁知道如何在MVC 5中使用剃刀视图来做到这一点?
这是我使用的从系统得到当前用户的密码:
public string getUserName()
{
displayName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
return displayName;
}
而且鉴于我目前的工作:
@model IEnumerable<BUUK.BSS.Models.User>
@{
ViewBag.Title = "MyTeam";
}
<h2>@ViewBag.Title</h2>
<h3>@ViewBag.Message</h3>
<p>
ViewBag.Title = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.Email)
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Email)
</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>
你能发布一些代码从你的看法?也请对你遇到的问题更具体一些。你是否收到任何编译错误或运行时异常消息? – SoftwareFactor 2014-08-28 08:02:46
纠正我,如果我错了,但你实际上在哪里使用'getUserName()'?它看起来不会在您发布的代码中的任何地方使用。 – 2014-08-28 08:16:22
这是从一个方法中获取活动目录中的名单 – SlipperyBalmain 2014-08-28 08:39:13