我需要创建和html辅助扩展,它接受boolean并根据布尔值返回字符串
public static string ConvertToString(this HtmlHelper helper, bool val)
{
if (val)
{
return "Y";
}
return "N";
}
问题是我如何将其与下面的telerik网格列集成。我想制作o.MultipleCurrencyFlag这是一个布尔应该给我Y或N
<% Html.Telerik().Grid(Model)
.Name("grid").Footer(false).Columns(columns =>
{
columns.Bound(o => o.MultipleCurrencyFlag).HtmlAttributes(new {@class = "currency"}).Title(Html.Resource("MultipleCurrencyTableHeader"));
}
).Pageable(pager => pager.PageSize(25))
.Footer(true)
.Render();
%>
下面代码需要将其更改为使用Html.ConvertToString(o.MultipleCurrencyFlag)
columns.Bound(o => o.MultipleCurrencyFlag)
.HtmlAttributes(new {@class = "currency"})
.Title(Html.Resource("MultipleCurrencyTableHeader"));
//编辑 我也试过
columns.Bound(o => o.MultipleCurrencyFlag)
.Format(Html.ConvertToString(o => o.MultipleCurrencyFlag))
.HtmlAttributes(new { @class = "currency" })
.Title(Html.Resource("MultipleCurrencyTableHeader"));
我无法让它发挥作用。
答案 0 :(得分:0)
假设您正在使用服务器绑定,这将为您完成:
columns.Template(o=> { %>
<%=Html.ConvertToString(o.MultipleCurrencyFlag)%>
<% })
.HtmlAttributes(new { @class = "currency"})
.Title(Html.Resource("MultipleCurrencyTableHeader"));
-Josh