This is a migrated thread and some comments may be shown as answers.

Namespace issue in an MVC3 Razor project.

14 Answers 1160 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Brady
Top achievements
Rank 1
Brady asked on 16 Dec 2010, 08:28 AM
Today I tried using the Telerik components in a Razor project for the first time.  I followed all setup instructions, but I got the following error:

CS1061: 'System.Web.Mvc.HtmlHelper<dynamic>' does not contain a definition for 'Telerik' and no extension method 'Telerik' accepting a first argument of type 'System.Web.Mvc.HtmlHelper<dynamic>' could be found 

I easily solved this by adding the following line to my master layout, but I am interested to know if anything can be done via web.config, as the normal namespace import in the Telerik instructions doesn't seem to work.

@using Telerik.Web.Mvc.UI

14 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 16 Dec 2010, 08:34 AM
Hello Brady,

We are aware of this limitation. It seems that Razor does not read the namespaces from web.config. We have tried reporting that to Microsoft but haven't got any response. I am afraid this is beyond our control.

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
a c
Top achievements
Rank 1
answered on 17 Dec 2010, 04:42 AM
in "yourProject/Views" folder, add a web.config file like following:

<?xml version="1.0"?>

<configuration>
  <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.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="System.Collections.Generic"/>
        <add namespace="System.Linq"/>       
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="Telerik.Web.Mvc"/>
        <add namespace="Telerik.Web.Mvc.UI"/>  
      </namespaces>
    </pages>
  </system.web.webPages.razor>

  <system.web>
    <httpHandlers>
      <add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
    </httpHandlers>

    <!--
        Enabling request validation in view pages would cause validation to occur
        after the input has already been processed by the controller. By default
        MVC performs request validation before a controller processes the input.
        To change this behavior apply the ValidateInputAttribute to a
        controller or action.
    -->
    <pages
        validateRequest="false"
        pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
        pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
        userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <controls>
        <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
      </controls>
    </pages>
  </system.web>

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
   
    <handlers>
      <remove name="BlockViewHandler"/>
      <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
    </handlers>
  </system.webServer>
</configuration>

0
Jason
Top achievements
Rank 1
answered on 21 Dec 2010, 05:06 PM
Adding the using statement worked for me.
Thanks!
0
Manoj Sharma*
Top achievements
Rank 1
answered on 11 Mar 2011, 06:23 PM

Solution

Add the following namespace entry to web.config in "Views" folder and it will work without @using statement
<add namespace="Telerik.Web.Mvc.UI" />

 

 

 

 

 

(doesn't work if you add namespace to main web.config)

0
Keith
Top achievements
Rank 1
answered on 03 Apr 2011, 05:26 PM
I added the namespace in the web.config under the Views folder and it did actually attempt to render the control, now, the stylesheets aren't loading I believe.  I could not find any documentation on how to get started with MVC3/Razor.  Any chance for a link to some decent setup documentation?

EDIT:
I added the Telerik extensions via NuGet and everything works fine :)
0
Sid
Top achievements
Rank 1
answered on 07 Apr 2011, 08:28 PM
I added the namespace in the Views/Shared web.config file, and my using statement still gives the error The Type Or Namespace Telerik could not be found.  How should this be rectified?
0
T. Tsonev
Telerik team
answered on 08 Apr 2011, 09:23 AM
Hello Sid,

Please make sure you add the namespace in the Views/web.config file, not Views/Shared/web.config

I hope this helps.

Regards,
Tsvetomir Tsonev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Sid
Top achievements
Rank 1
answered on 08 Apr 2011, 10:33 PM
Hi,

The MenuPartial.cshtml is located in Views/Shared.  I modified the web.config in the Views as well as under the main project.  Unfrotunately, I'm still unable to call the using statement.  Is there a better location to place the MenuPartial.cshtml instead of in the shared directory?  It's going to be used in the master page etc.

Thanks,
Sid
0
T. Tsonev
Telerik team
answered on 11 Apr 2011, 08:12 AM
Hello Sid,

The location of the view shouldn't matter as long as it in the Views folder and not in a separate Area. Can you please send us a stripped-down version of your project so we can debug it locally.

Greetings,
Tsvetomir Tsonev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Sid
Top achievements
Rank 1
answered on 11 Apr 2011, 11:41 PM
Hi,

This issue is now resolved after building the solution. 

Thanks,
Sid
0
Steven
Top achievements
Rank 2
answered on 24 Sep 2011, 09:13 PM

Try this in your web.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="System.Web.Mvc.WebViewPage">
        <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.Routing" />
            <add namespace="System.Web.WebPages" />
            <add namespace="Telerik.Web.Mvc.UI" />
            <add namespace="Telerik.Web.Mvc.Configuration"/>
        </namespaces>
    </pages>
</system.web.webPages.razor>
0
David
Top achievements
Rank 1
answered on 16 Dec 2011, 11:11 AM
Please ignore, I replied to the wrong comment.
0
Douglas
Top achievements
Rank 1
answered on 03 Apr 2012, 08:51 PM
this fix did not work for me
0
Sree
Top achievements
Rank 1
answered on 12 Oct 2012, 10:15 AM
Hi Telerik Team,
I wanted to use cascade combo box in my project. I am not able to get the method "cascadeto" for combobox.It showing error
"Telerik.Web.Mvc.UI.Fluent.DropDownListBuilder' does not contain a definition for 'CascadeTo' and no extension method 'CascadeTo' accepting a first argument of type 'Telerik.Web.Mvc.UI.Fluent.DropDownListBuilder' could be found (are you missing a using directive or an assembly reference?)"

My Telerik.web.mvc dll version id "2011.2.712.340"..What shall I do now. Shall I use 2012 build. I was not able to down load even trial version of 2012 from ur site.

Thank you,
sree
MyEmail:sreekumargupta@gmail.com
Tags
General Discussions
Asked by
Brady
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
a c
Top achievements
Rank 1
Jason
Top achievements
Rank 1
Manoj Sharma*
Top achievements
Rank 1
Keith
Top achievements
Rank 1
Sid
Top achievements
Rank 1
T. Tsonev
Telerik team
Steven
Top achievements
Rank 2
David
Top achievements
Rank 1
Douglas
Top achievements
Rank 1
Sree
Top achievements
Rank 1
Share this question
or