获取属于ASP.Net MVC中特定用户的数据列表

问题描述

如果我当前在sql Server的属性表中有此数据

PropertyID  PropertyName   UserID
1           prop1          User1
2           prop2          User1
3           prop3          User1
4           prop4          Admin
5           prop5          Admin

我只想根据已验证的用户进行查看。例如,User1已登录,则“属性视图”中要显示的项目必须仅在下面,(但当用户为Admin时,它将显示所有内容

 PropertyID  PropertyName   UserID
    1           prop1          User1
    2           prop2          User1
    3           prop3          User1

这是使用Entity Framework创建带有视图的Controller> MVC 5 Controller的代码片段

enter image description here

 public class PropertyController : Controller
    {
        private ApplicationDbContext db = new ApplicationDbContext();

        // GET: Property
        [Authorize]
        public async Task<ActionResult> Index()
        {
            return View(await db.Property.ToListAsync());
           
        }

以上代码显示了表中的所有数据,我如何有条件地实现仅显示属于特定用户的数据?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)