views:

28

answers:

1

Hi

I need some help creating this extenstion method.

My View page enherits from

       <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/NoSideMenu.Master"
Inherits="System.Web.Mvc.ViewPage<List<MyProject.Models.Customer>>" %>




      <% Html.Telerik().Grid(Model)
        .Name("customer-history-grid").Footer(false).Columns(columns =>
        {
            columns.Bound(o => o.IsValidCustomer).Title(Html.Resource("ValidCustomerTableHeader"));

        }
        ).Pageable(pager => pager.PageSize(25))
        .Footer(true)
        .Render(); 

    %>

Here I don't want to display the boolean value. Instead I want to display "Y" or "N". For example if o.IsValidCustomer is true then "Y" else "F"

I tried writing below

Extensions...

   public static string ConvertToString<T, TValue>(this HtmlHelper<T> helper, Expression<Func<T, TValue>> expression)
    {
       ......
    }

But my extenstion method picks up the > type and not the Customer object. So I cannot select the method (o.IsValidCustomer) in the lamda expression for example

in View...

      columns.Bound(o => o.IsValidCustomer).Format(Html.ConvertToString(o => o.IsValidCustomer)).Title(Html.Resource("ValidCustomerTableHeader"));

Please help.

A: 

Would it be possible to edit your domain model?

E.g. add this

public string IsValidCustomerString
{
    get { return IsValidCustomer ? "Y" : "N"; }
}

Then just bind that as a column?

HTHs,
Charles

Charlino
Yeah I like that. and your solution should work. However I did it in another way. Telerik provide a template helper so we can call the Html helper method as belowcolumns.Template(o => { %> <%= Html.ConvertBooleanToYOrN(o.MultipleCurrencyFlag)%> <% }).HtmlAttributes(new { @class = "flag" }).Title(Html.Resource("MultipleCurrencyTableHeader"));Thanks alot and appreciate your suggession.
Simon