0

I'm trying to create a custom HtmlHelper for kendogrid to use with parameters.
My problem is how to refact my viewmodel to accept an interface the htmlhelper?
here is my htmlhelper class

using System;
using System.Web.Mvc;
using Kendo.Mvc.UI;
using System.Linq;
using Popup.BLL.ViewModel;

namespace Popup.Web.KendoHelper
{
    public static class PickListHelper
    {
        public static Kendo.Mvc.UI.Fluent.GridBuilder<T> PickList<T>(this HtmlHelper helper, string gridName, string gridClass, int gridHeight)
             where T : class
        {
            return helper.Kendo().Grid<T>()
            .Name(gridName)
                    .Columns(columns =>
                    {
                        columns.Bound(c => c.Text).Title("Associated");
                    })
            .HtmlAttributes(new { @class = gridClass, style = "height: " + gridHeight + "px;" })
            .Scrollable()
            .Sortable()
            .Selectable(selectable => selectable
                .Mode(GridSelectionMode.Multiple))
            .Events(events => events.Change("onSelectAssociatedGridElements"))
            .DataSource(datasource => datasource.Ajax().Read(read => read.Data("getAssociatedGridDataSource")));

        }
    }
}`

and my viewmodel class

public class TextViewModel
    {
       public int Id { get; set; }
       public string Text { get; set; }
    }

problem: c => c.Text
MSVS: Cannot convert lambda expression to type 'string' because it is not a delegate type

Kukher
  • 3
  • 2
  • 1
    Already this Text is string itself. – Shajeer Puzhakkal Mar 03 '16 at 13:17
  • How compiler know if `T` class has `Text` property? it should be `return helper.Kendo().Grid()` – Gene R Mar 03 '16 at 13:42
  • 1
    change `where T : class` to `where T : TextViewModel` and see if it works – th1rdey3 Mar 03 '16 at 14:27
  • 1
    you are using columns.Bound(c=>c.Text) in your extension helper where you are passing Anonymous T (compiler will not know that T contains Text property) , you can the idea mentioned by @th1rdey3 or to create an interface that has property Text which I recommend – Monah Mar 03 '16 at 14:32
  • yeah it works, thanks. later ill create an interface for it – Kukher Mar 03 '16 at 14:35

1 Answers1

0
 .Columns(columns =>
  {
    columns.Bound(c => c).Title("Text");
  })
Moumit
  • 8,314
  • 9
  • 55
  • 59