asp.net-mvc-3 - Web 网格 MVC 3 - 用于检查条件的 If 语法

标签 asp.net-mvc-3

我这里有一个语法错误,请问有人可以指出这是什么吗?

我有来自 Controller 的 ViewBag.IsAdmin

//code- I am writing this in a view-webgrid
grid.Column(format : (item) => {
                                 if(ViewBag.isAdmin)
                                  {

                                          Html.ActionLink("Edit", "EditSingleAbsence","Absence", new { AbsenceId = item.id }, null);
                                  }
                               }
          )    
/code ended

它符合以下错误:

  CS1502: The best overloaded method match for 'System.Web.Helpers.WebGrid.Column(string, string, System.Func<dynamic,object>, string, bool)' has some invalid arguments

我从这里找到了答案

Here 解决方案

不需要使用if条件..

grid.Column(format:(item) => ViewBag.isAdmin ? Html.ActionLink("Edit", "EditSingleAbsence", "Absence", new { AbsenceId = item.id }, null) : Html.Raw("")) 

最佳答案

工作解决方案

谷歌搜索后,这对我有用。我从 Here 得到了这个解决方案

grid.Column(format:(item) => ViewBag.isAdmin ? Html.ActionLink("Edit", "EditSingleAbsence", "Absence", new { AbsenceId = item.id }, null) : Html.Raw("")) 

关于asp.net-mvc-3 - Web 网格 MVC 3 - 用于检查条件的 If 语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6466588/

相关文章:

asp.net-mvc-3 - MVC3 JQuery AJAX ||多个传递的参数为空

asp.net-mvc - Linq 左外连接无法使用 DefaultIfEmpty 工作

jquery - MVC 3 在数据库中保存复选框状态

javascript - 无法序列化在 Controller 中使用两个参数的帖子

asp.net-mvc - 将我的项目 namespace 添加到MVC web.config

c# - MVC 多区域 MVC 3

asp.net-mvc-3 - wwwroot 之外的 Elmah logPath

asp.net - 无法将 'ASP._Page__ViewStart_cshtml' 类型的对象转换为 'System.Web.WebPages.StartPage' 类型

c# - ASP.NET MVC 自定义成员资格提供程序 - 如何重载 CreateUser?

c# - MVC 3 中的某些页面不显示菜单?