Asp.net mvc 3 asp.net-MVC基于角色编辑GridDate

Asp.net mvc 3 asp.net-MVC基于角色编辑GridDate,asp.net-mvc-3,datagrid,role,Asp.net Mvc 3,Datagrid,Role,我有一个datagrid来显示员工的具体情况,但我需要在其中设置一个逻辑 如果Role=Manager,则显示所有员工,如果Role=employee,则仅显示属于他的1个数据。下面是我向员工展示的代码。我设法让所有员工都看到了。需要帮助为员工设置筛选器 看法 控制器 public ActionResult GridData (string sidx, string sord, int page, int rows) {

我有一个datagrid来显示员工的具体情况,但我需要在其中设置一个逻辑 如果Role=Manager,则显示所有员工,如果Role=employee,则仅显示属于他的1个数据。下面是我向员工展示的代码。我设法让所有员工都看到了。需要帮助为员工设置筛选器

看法

控制器

     public ActionResult GridData (string sidx, string sord, int page, int rows)
            {             
                int pageIndex = Convert.ToInt32(page) - 1;
                int pageSize = rows;
                int totalRecords = db.VOC_CUSTODIAN.Count();
                int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);   
                var jsonData = new
                               {
                                   total = totalPages,
                                   page = page,
                                   records = totalRecords,
                                   rows = (from custo in db.VOC_CUSTODIAN.AsEnumerable()
                                          select new
                                                 {
                                                     id = custo.Idx,
                                                     cell = new string []
                                                            {
                                                                custo.StaffId, 
                                                                custo.Branch,
                                                                custo.UniqueId,
                                                                custo.Name,
                                                                custo.Role,
                                                                ("<a href='"+ @Url.Action("Details", "Custodian") +"/"+ custo.Idx+ "'>DETAILS</a>"),
                                                                ("<a href='"+ @Url.Action("Edit", "Custodian") +"/"+ custo.Idx+ "'>EDIT</a>"),
                                                                ("<a href='"+ @Url.Action("Delete", "Custodian") +"/"+ custo.Idx+ "'>DELETE</a>")
}
                                                 }).ToArray()
                               };
                return Json(jsonData, JsonRequestBehavior.AllowGet);
            }

视图不应处理逻辑,控制器操作应处理逻辑。您应该能够通过以下方式执行类似操作:


我遇到此错误..嵌入语句不能是声明或带标签的语句。您没有提供足够的错误信息,我无法提供帮助。哪一行代码等。
     public ActionResult GridData (string sidx, string sord, int page, int rows)
            {             
                int pageIndex = Convert.ToInt32(page) - 1;
                int pageSize = rows;
                int totalRecords = db.VOC_CUSTODIAN.Count();
                int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);   
                var jsonData = new
                               {
                                   total = totalPages,
                                   page = page,
                                   records = totalRecords,
                                   rows = (from custo in db.VOC_CUSTODIAN.AsEnumerable()
                                          select new
                                                 {
                                                     id = custo.Idx,
                                                     cell = new string []
                                                            {
                                                                custo.StaffId, 
                                                                custo.Branch,
                                                                custo.UniqueId,
                                                                custo.Name,
                                                                custo.Role,
                                                                ("<a href='"+ @Url.Action("Details", "Custodian") +"/"+ custo.Idx+ "'>DETAILS</a>"),
                                                                ("<a href='"+ @Url.Action("Edit", "Custodian") +"/"+ custo.Idx+ "'>EDIT</a>"),
                                                                ("<a href='"+ @Url.Action("Delete", "Custodian") +"/"+ custo.Idx+ "'>DELETE</a>")
}
                                                 }).ToArray()
                               };
                return Json(jsonData, JsonRequestBehavior.AllowGet);
            }
if (!Roles.IsUserInRole(User.Identity.Name, "Managers"))
{
  jsonData.total = 1;
  jsonData.page = 1;
  jsonData.records = 1;
  jsonData.rows = jsonData.rows.Where(x => x.id = currentUserId).ToArray() 
}

return Json(jsonData, JsonRequestBehavior.AllowGet);