4

I am trying to use the Kendo UI MVC wrappers with ServiceStack Razor Views.

I've followed the directions as per Kendo UI Instructions in the hope that it'd be straight forward.

@Html. doesn't reveal a Kendo extension in my cshtml pages.

Could anyone kindly offer some guidance?

  • I updated the sections as Atanas Korchev requested

    <compilation debug="true" targetFramework="4.5">
      <!-- Service Stack Razor View Build Provider -->
      <buildProviders>
        <add extension=".cshtml" type="ServiceStack.Razor.CSharpRazorBuildProvider, ServiceStack.Razor, Version=2.1.*, Culture=neutral" />
      </buildProviders>
      <assemblies>
        <add assembly="ServiceStack"/>
        <add assembly="ServiceStack.Razor"/>
        <add assembly="ServiceStack.Text" />
        <add assembly="Kendo.Mvc"/>
        <add assembly="WebApplication1" />
    <!-- MVC 3 Added at Atanas Korchev's request -->
    <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      </assemblies>
    </compilation>
    
  • (for some reason it refuses to show the code sampe, but I added the Mvc namespaces too, to the correct section)

It now throws the error:

'ServiceStack.Html.HtmlHelper<dynamic>' 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}
  • I pasted in @(Html.Kendo().DatePicker().Name("Birthday")) to my view and attempt compile, as per Atanas' request to get this error

  • I am thinking a solution is not possible without some source changes to handle ServiceStack's HtmlHemlper?

Original Web.config

<?xml version="1.0"?>

<configuration>

  <!-- Separate config section for each at the bottom of web.config -->
  <configSections>
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    </sectionGroup>
  </configSections>

  <system.web>
    <compilation debug="true" targetFramework="4.5">
      <!-- Service Stack Razor View Build Provider -->
      <buildProviders>
        <add extension=".cshtml" type="ServiceStack.Razor.CSharpRazorBuildProvider, ServiceStack.Razor, Version=2.1.*, Culture=neutral" />
      </buildProviders>
      <assemblies>
        <add assembly="ServiceStack"/>
        <add assembly="ServiceStack.Razor"/>
        <add assembly="ServiceStack.Text" />
        <add assembly="Kendo.Mvc"/>
        <add assembly="WebApplication1" />
      </assemblies>
    </compilation>
    <httpRuntime targetFramework="4.5" />
  </system.web>

  <!-- Register ServiceStack to listen on root path of web server -->
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
      <add path="*" name="ServiceStack.Factory" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" />
    </handlers>
  </system.webServer>


  <appSettings>
    <!-- Enables ServiceStack.Razor pages -->
    <add key="webPages:Enabled" value="false" />
  </appSettings>

  <!-- ServiceStack.Razor Config -->
  <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="ServiceStack.Razor.ViewPage">
      <namespaces>
        <!-- Make these namespaces available to razor views-->
        <!-- Required for ServiceStack -->
        <add namespace="ServiceStack.Html" />
        <add namespace="ServiceStack.Razor" />
        <add namespace="ServiceStack.Text" />

        <!-- Business -->
        <add namespace="WebApplication1" />

        <!-- Kendo UI MVC Wrappers -->
        <add namespace="Kendo.Mvc.UI" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>

</configuration>

4 Answers 4

1

Note: The following does not intend to reflect a negative opinion of either ServiceStack or KendoUI. They are both amazing. These products are just incompatible by nature. The intended purpose of this question was to investigate the feasibility of this nature


After looking through the source-code of Kendo.Mvc in detail, I've concluded that Kendo.Mvc is not suitable and undesirable for use with ServiceStack Razor.

This is because:

  • ServiceStack's Razor has no dependency on System.Web.Mvc and Kendo.Mvc reintroduces it
  • ServiceStack has its own implementation of classes like HtmlHelper, ViewPage and other key classes that Kendo.Mvc rely on the System.Web.Mvc equivalent of.
  • I am yet to find a clear way to easily separate the Kendo.Mvc's dependency on MVC Controllers (which ServiceStack razor views do not use). The hopewas to be simply able to configure Widgets in razor in a type-safe way to be rendered to the html, tied to the Model.

I'll resort to writing my own Helpers, using something like this StackOverflow Q&A as an approach.

2
  • Seems this is the best thing to do. Kendo UI for MVC depends on System.Web.Mvc a lot and you can't really took those out. Dec 24, 2012 at 8:21
  • Just for completition, here is an official answer from Telerik: KendoUI with SS
    – nhaberl
    Feb 27, 2014 at 13:58
1

I had the same problem, but solved it by adding the following namespaces to my web.config.

<add namespace="Kendo"/>
<add namespace="Kendo.Mvc"/>
<add namespace="Kendo.Mvc.Extensions"/>
<add namespace="Kendo.Mvc.Ui"/>

I think the key one here is add namespace="Kendo.Mvc.Ui"

1

Update the web.config in Views folder with

<add namespace="Kendo.Mvc.UI"/>
-1

You need to add the relevant namespaces in the web.config file in the Views folder, not in the main web.config file in the top folder. Just read the instructions carefully.

1
  • They are inherited automatically in the views Folder. web.config works like that... The problem is specifically with trying to use ServiceStack razor... It has its own implementation of System.Web.Mvc.HtmlHelper, as my last edit mentions
    – Tyst
    Dec 22, 2012 at 10:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.