我目前正在做一个小而简单的项目。我有一个存储在数据库中的用户列表,如下所示:Id(唯一标识符主键),FirstName(varchar),LastName(varchar),PhoneNo(varchar),DomainAC(varchar)
我在这样的网页上显示他们的信息:
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<IEnumerable<WhoIs.Models.Employee>>" %>
<!DOCTYPE html>
<html>
<head runat="server">
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<p>
<%: Html.ActionLink("Create New", "Create") %>
</p>
<table>
<tr>
<th>
<%: Html.DisplayNameFor(model => model.FullName) %>
</th>
<th>
<%: Html.DisplayNameFor(model => model.PhoneNo) %>
</th>
<th>
<%: Html.DisplayNameFor(model => model.DomainAC) %>
</th>
<th>
<%: Html.DisplayNameFor(model => model.Branch) %>
</th>
<th></th>
</tr>
<% foreach (var item in Model) { %>
<tr>
<td>
<%: Html.DisplayFor(modelItem => item.FullName) %>
</td>
<td>
<%: Html.DisplayFor(modelItem => item.PhoneNo) %>
</td>
<td>
<%: Html.DisplayFor(modelItem => item.DomainAC) %>
</td>
<td>
<%: Html.DisplayFor(modelItem => item.Branch) %>
</td>
<td>
<% if (User.IsInRole(@"Admin") || User.Identity.Name == item.DomainAC) {%>
<%: Html.ActionLink("Edit", "Edit", new { id=item.Id }) %> |
<%: Html.ActionLink("Delete", "Delete", new { id=item.Id }) %>
<% } %>
</td>
</tr>
<% } %>
</table>
</body>
</html>
这工作正常,它会抛出一个用户的小网页,并在他们旁边显示 3 个毫无意义的链接 - 但我不确定从这里去哪里 - 我如何使这些链接尽可能简单/有效地工作?
我想要的功能很简单
if(DomainAC == currently logged in Domain AC || currently logged in Domain AC is admin)
Allow user to edit/update details.
else
{
user is normal, no buttons/actions - just display the list.
}
谁能简单地向我解释一下我需要做些什么来完成这项工作?我之前发布了一个与此类似的问题,它真的让我头疼 - 谈论 ActionControllers 等,没有解释它们在你的项目中的位置/它们如何链接在一起/如何使用它们。
任何人都可以帮我解决这个问题吗?我将在两天内对此进行小额赏金并将其授予最佳答案,因为这是最近对我来说经常出现的事情!谢谢你。