c# - 有没有办法根据登录名显示数据?
问题描述
我想把它放在用户登录时他们只能根据他们的电子邮件看到表格中的信息的地方。
我对编码非常陌生,并且大部分工作都是从头开始完成的,但似乎无法弄清楚我正在处理的这个问题是如何解决的。
目前,我在@user.identity.name
提交新表单时使用他们的电子邮件。任何帮助都会很棒!谢谢你。
索引页
@model IEnumerable<WebApplication1.Models.Ticket>
@{
ViewData["Title"] = "Index";
}
<h1>Tickets</h1>
<p>
<a asp-action="Create">Create New</a>
</p>
<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.Email)
</th>
<th>
@Html.DisplayNameFor(model => model.Phone)
</th>
<th>
@Html.DisplayNameFor(model => model.Date)
</th>
<th>
@Html.DisplayNameFor(model => model.Location)
</th>
<th>
@Html.DisplayNameFor(model => model.Severity)
</th>
<th>
@Html.DisplayNameFor(model => model.Issue)
</th>
<th>
@Html.DisplayNameFor(model => model.Details)
</th>
<th>
@Html.DisplayNameFor(model => model.Viewed)
</th>
<th>
@Html.DisplayNameFor(model => model.Resolved)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Email)
</td>
<td>
@Html.DisplayFor(modelItem => item.Phone)
</td>
<td>
@Html.DisplayFor(modelItem => item.Date)
</td>
<td>
@Html.DisplayFor(modelItem => item.Location)
</td>
<td>
@Html.DisplayFor(modelItem => item.Severity)
</td>
<td>
@Html.DisplayFor(modelItem => item.Issue)
</td>
<td>
@Html.DisplayFor(modelItem => item.Details)
</td>
<td>
@Html.DisplayFor(modelItem => item.Viewed)
</td>
<td>
@Html.DisplayFor(modelItem => item.Resolved)
</td>
<td>
<a asp-action="Edit" asp-route-id="@item.EmployeeID">Edit</a> |
<a asp-action="Details" asp-route-id="@item.EmployeeID">Details</a> |
<a asp-action="Delete" asp-route-id="@item.EmployeeID">Delete</a>
</td>
</tr>
}
</tbody>
</table>
票种模型
namespace WebApplication1.Models
{
public class Ticket
{
[Key]
public int EmployeeID { get; set; }
[Column(TypeName ="varchar(50)")]
public string Email { get; set; }
[Column(TypeName = "varchar(50)")]
[Required(ErrorMessage ="This field is required.")]
public string Phone { get; set; }
[Column(TypeName = "varchar(50)")]
public string Date { get; set; }
[Column(TypeName = "varchar(50)")]
[Required(ErrorMessage = "This field is required.")]
public string Location { get; set; }
[Column(TypeName = "varchar(50)")]
public string Severity { get; set; }
[Column(TypeName = "varchar(50)")]
[Required(ErrorMessage ="This field is required.")]
public string Issue { get; set; }
[Column(TypeName = "varchar(Max)")]
public string Details { get; set; }
[Column(TypeName = "varchar(50)")]
public string Viewed { get; set; }
[Column(TypeName = "varchar(50)")]
public string Resolved { get; set; }
}
}
解决方案
推荐阅读
- python - 如何在其他文件中使用事件?
- mysql - 从另一个模型验证其值的表单的验证错误引发
- sql - 子查询返回超过 1 个值 - STIntersects
- spring - Spring State Machine:可能的事件
- excel - 在 vba 代码中引用另一个工作表上的范围以将公式复制到最后一行数据
- sql - sql查询检查至少存在2条记录
- python - 如何使用 exec() 将值传递给 python 函数中的变量?
- node.js - 如何将图像传递到 AWS SageMaker 端点
- javascript - sass-loader 前置 @import
- aspnet-contrib - 集成 AspNet.Security.OpenId.Providers Steam 授权与 reactive.js?