首页 > 解决方案 > 有没有办法根据登录名显示数据?

问题描述

我想把它放在用户登录时他们只能根据他们的电子邮件看到表格中的信息的地方。

我对编码非常陌生,并且大部分工作都是从头开始完成的,但似乎无法弄清楚我正在处理的这个问题是如何解决的。

目前,我在@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; }
    }
}

标签: c#html

解决方案


推荐阅读