我知道我可以在.ClientTemplate中使用if条件,但是如何在客户端模板和列模板之外执行此操作?例如,我有一个列操作链接,单击该链接将转到新表单。我想要一个条件,如果为true,则显示操作链接图标,否则显示不可点击的图标。下面我的一个列的示例代码
columns.Template(
@<text>
@Html.ActionLink("New", "CreateFormsIndex", new { Controller = "Forms", id = "#=ProjectId#", revDt = "#=NextReviewDate#" })
</text>)
.ClientTemplate("<a href='/ProjectManagers/Forms/CreateFormsIndex?id=#=ProjectId#&revDt=#=NextReviewDate#'><span class=\"fa fa-file-o\"></span></a>")
.Title("New Review")
.HeaderHtmlAttributes(new { style = "text-align: center" })
.HtmlAttributes(new { style = "text-align: center" });
答案 0 :(得分:0)
尝试使用以下代码段。
.ClientTemplate(" # if (YourField) { #" +
"<a href='/ProjectManagers/Forms/CreateFormsIndex?id=#=ProjectId#&revDt=#=NextReviewDate#'><span class=\"fa fa-file-o\"></span></a>" +
"# } else { #" +
"<span class=\"fa fa-file-o\"></span>" +
"# } #")