Kendo UI reference not working in Razor view

2020-07-03 03:32发布

I am trying to create a Telerik Grid view but when I go to reference kendo it does not recognize it. Visual Studio is giving me an error when I try to reference kendo. This is the code @(Html.Kendo().Grid) and below is the error.

'System.Web.Mvc.HtmlHelper<dynamic>' does not contain a definition for 'Kendo' and no extension method 'Kendo' accepting a first argument of type 'System.Web.Mvc.HtmlHelper<dynamic>' could be found (are you missing a using directive or an assembly reference?)

I have added a bundle in the BundleConfig file for both Scripts and Content. Also I have added @Scripts.Render("~/bundles/kendo") and @Styles.Render("/Content/kendo") directly to the razor view.

Many articles that i've read suggest that adding <add namespace="Kendo.Mvc.UI"/> to the Web.Config file would work but it still is throwing out the same error.

Is there something that I am missing?

9条回答
forever°为你锁心
2楼-- · 2020-07-03 03:59

I just added the below line in razor page. Its working for me.

@using Kendo.Mvc.UI;

查看更多
够拽才男人
3楼-- · 2020-07-03 04:00

Step1: Add Kendo.Mvc.dll to references. You can use the following NuGet gallery command.

Install-Package Kendo.Mvc -Version {yourversion}

Step2: Add the js and css File of Kendo

<link href="@Url.Content("~/Content/kendo/2017.3.1018/kendo.common.min.css")" rel="stylesheet" type="text/css" />

<link href="@Url.Content("~/Content/kendo/2017.3.1018/kendo.mobile.all.min.css")" rel="stylesheet" type="text/css" />

<link href="@Url.Content("~/Content/kendo/2017.3.1018/kendo.dataviz.min.css")" rel="stylesheet" type="text/css" />

<link href="@Url.Content("~/Content/kendo/2017.3.1018/kendo.default.min.css")" rel="stylesheet" type="text/css" />

<link href="@Url.Content("~/Content/kendo/2017.3.1018/kendo.dataviz.default.min.css")" rel="stylesheet" type="text/css" />

<script src="@Url.Content("~/Scripts/kendo/2017.3.1018/jquery.min.js")"></script>

<script src="@Url.Content("~/Scripts/kendo/2017.3.1018/jszip.min.js")"></script>

<script src="@Url.Content("~/Scripts/kendo/2017.3.1018/kendo.all.min.js")"></script>

<script src="@Url.Content("~/Scripts/kendo/2017.3.1018/kendo.aspnetmvc.min.js")"></script>

<script src="@Url.Content("~/Scripts/kendo.modernizr.custom.js")"></script>

Step3: Add the Kendo.Mvc.UI namespace in web.config file.

note: if use the Area in Project you should add this code to web.config of Area.

<system.web>
    <pages>
        <namespaces>
            <add namespace="Kendo.Mvc.UI" />
        </namespaces>
    </pages>
</system.web>
查看更多
4楼-- · 2020-07-03 04:01

I had the same problem. The third point mentioned below solved the problem in my case.

1. Include the JavaScript and CSS files: The ordering of scripts and css files is also very important. jQuery should be included before the KendoUI script file(s).

2. Add reference to Kendo.Mvc.dll: Right-click the References node in Solution Explorer and click Add Reference. Select the Browse tab of the Add Reference dialog and navigate to the install location of Telerik UI for ASP.NET MVC.

3. Update the web.config in Views folder: Open Views/Web.config (or root Web.config if using ASPX). Locate the namespaces tag. Append an below add tag to the namespaces tag.

<add namespace="Kendo.Mvc.UI" />
查看更多
\"骚年 ilove
5楼-- · 2020-07-03 04:06

AddKendo.Mvc.dll through NugetPackage and Add Kendo.Mvc

Add Namespace in webconfig file

<system.web>
<pages>
    <namespaces>
        <add namespace="Kendo.Mvc.UI" />
    </namespaces>
</pages>

enter image description here

enter image description here

enter image description here

enter image description here

查看更多
Juvenile、少年°
6楼-- · 2020-07-03 04:08

The problem is that you have not included a reference to the Kendo.Mvc.dll. There's an explanation on how to do this in the documentation located here

By default the the root kendo directory is installed at C:\Program Files (x86)\Telerik

查看更多
一纸荒年 Trace。
7楼-- · 2020-07-03 04:11

For me, it was _ViewImports.cshtml that I needed to edit

@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, Kendo.Mvc
@using Kendo.Mvc.UI

Now with asp.net core 2.2 the razor page is resolving the @(Html.Kendo()...

查看更多
登录 后发表回答