sevargdcg
sevargdcg

Reputation: 305

Using Kendo UI in app_code/helper.cshtml file

I am trying to extract out duplicated code into an Html.Helpers class. I am able to use the helper class with simple html, but when I try to use the Kendo UI extensions I get and error. saying that:

CS1928: 'System.Web.WebPages.Html.HtmlHelper' does not contain a definition for 'Kendo' and the best extension method overload 'Kendo.Mvc.UI.HtmlHelperExtension.Kendo(System.Web.Mvc.HtmlHelper)' has some invalid arguments

Any help or workaround to get this to work is appreciated. I want to keep the file in the app_code folder if possible due to standards compliance.

Code in .cshtml file

@using Kendo.Mvc.UI

@helper LEASearch(string name)
{
    @(Html.Kendo().AutoComplete()
        .Name(name)
        .Filter("contains")
        .Placeholder("Entity ID, CTDS or Name")
        .MinLength(2)
        .HtmlAttributes(new { style = "width:390px" })
        .DataSource(source => source.Read(read => read.Action("SearchLEAList", "DataPush")
                                                    .Data("onLEASearchIncluded"))
                                    .ServerFiltering(true)).Events(events=> events.Select("selectLEAIncluded"))
        .Template("<h5 data_entity=\"${data.EntityID}\""+
                " data_ctds=\"${data.CTDS}\" data_name=\"${data.Name}\">"+
                "ID:${data.EntityID} &nbsp;&nbsp; CTDS:${data.CTDS}</h5>"+
                "<p>${data.Name}</p>")
        );
}

Web.config system.web namespaces

    <pages>
  <namespaces>
    <add namespace="System.Web.Helpers" />
    <add namespace="System.Web.Mvc" />
    <add namespace="System.Web.Mvc.Ajax" />
    <add namespace="System.Web.Mvc.Html" />
    <add namespace="System.Web.Optimization" />
    <add namespace="System.Web.Routing" />
    <add namespace="System.Web.WebPages" />
    <add namespace="Kendo.Mvc.UI"/>
  </namespaces>
</pages>

View/Web.config Razor section

  <system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
  <namespaces>
    <add namespace="System.Web.Mvc" />
    <add namespace="System.Web.Mvc.Ajax" />
    <add namespace="System.Web.Mvc.Html" />
    <add namespace="System.Web.Optimization"/>
    <add namespace="System.Web.Routing" />
  </namespaces>
</pages>

Upvotes: 2

Views: 1873

Answers (1)

Atanas Korchev
Atanas Korchev

Reputation: 30661

It looks as if accessing HtmlHelper extension methods isn't supported. Here is what i found in the ASP.NET forums: http://forums.asp.net/t/1799665.aspx

Upvotes: 2

Related Questions