I need to create and html helper extension which takes boolean and returns string depending on the boolean value
开发者_如何学Python public static string ConvertToString(this HtmlHelper helper, bool val)
{
if (val)
{
return "Y";
}
return "N";
}
The problem is how can I intergrate this to the below telerik grid column. I want to make the o.MultipleCurrencyFlag which is a boolean should give me Y or 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();
%>
Below code need to change it to use the Html.ConvertToString(o.MultipleCurrencyFlag)
columns.Bound(o => o.MultipleCurrencyFlag)
.HtmlAttributes(new {@class = "currency"})
.Title(Html.Resource("MultipleCurrencyTableHeader"));
//edit I also tried
columns.Bound(o => o.MultipleCurrencyFlag)
.Format(Html.ConvertToString(o => o.MultipleCurrencyFlag))
.HtmlAttributes(new { @class = "currency" })
.Title(Html.Resource("MultipleCurrencyTableHeader"));
I cannot get this to work.
Assuming you are using server binding, this will do it for you:
columns.Template(o=> { %>
<%=Html.ConvertToString(o.MultipleCurrencyFlag)%>
<% })
.HtmlAttributes(new { @class = "currency"})
.Title(Html.Resource("MultipleCurrencyTableHeader"));
-Josh
精彩评论