开发者

How to add the Html helper extension to this grid?

开发者 https://www.devze.com 2023-01-12 09:09 出处:网络
I need to create and html helper extension which takes boolean and returns string depending on the boolean value

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

0

精彩评论

暂无评论...
验证码 换一张
取 消