Kendo UI with asp.net - asp.net

Hi can someone tell me how to use Kendo UI with asp.net web application?
Because when I try to create an asp.net application and added kendo.mvc.dll in my bin folder.
Now I've added
<%= Html.Kendo().Calendar().Name("calendar") %>
in my default.aspx page. Now it is saying "The name HTML does not exist in the current context"
Can someone help me what is the issue in that?
Thanks in advance

You are trying to use Kendo for MVC when your web application is not MVC.
You need to use Kendo UI WEB
http://www.kendoui.com/download.aspx

Why don't you follow these simple steps from the documentation?
http://docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/introduction#manually-add-kendo-ui-to-aspnet-mvc-applications
In particular I'm referring to the step 7 where you must add the namespece in your web.config:
<namespaces>
<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.Linq" />
<add namespace="System.Collections.Generic" />
<add namespace="Kendo.Mvc.UI" />
</namespaces>

Related

Import namespace globally in ASP.NET views without #using

In my ASP.NET MVC 5 Application I have all my models in the namespace MyApp.Models. To use the model inside my view, e.g. to tell the view which model he should use with #model UserLoginModel, I have to import the namespace with using MyApp.Models.
Thats not a big deal but I would prefer it to include this namespace automatically in every of my views to avoid redundant importing in every view. I found out that the web.config file in my views-folder seems to be right for this job
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.Optimization"/>
<add namespace="MyApp" />
<add namespace="MyApp.Models"/>
</namespaces>
</pages>
But its not working. All of this was pre-generated by Visual Studio. I only added the <add namespace="MyApp.Models"/> for my models.
On SO I found a similar question like my but the asker only say that it should work by using the Views/web.config file as I tried and the answears follow his question which is specified to the new beta of ASP.NET MVC 6. But I'm using MVC 5.1.2 and cant get make this work, he can't find the view without including the namespace with #using in the view.

#Html.EditorFor is Not Available inside the View

I am using Visual Studio 2013 Web Express. In my ASP.NET MVC application view I cannot call or even see the #Html.EditorFor method. The intellisense never pops it up.
Any ideas?
EDITED: Same goes with #Html.BeginForm. The method never pops up!
It sounds like the namespace is not available.
In the first instance, try adding
#using System.Web.Mvc.Html
at the top of your view to see if that helps. If it does, then there is probably a problem with your View specific Web.config. In the root of your Views folder there should be a Web.config file. Note that if you use Areas then there should be one of those in each Views folder.
Inside that Web.config there should be a section like the following:
<configuration>
...other stuff...
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.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" />
<add namespace="WebApplication1" />
</namespaces>
</pages>
</system.web.webPages.razor>
...other stuff...
</configuration>
Essentially that section is the equivalent of adding using statements inside each view.

MVC2 Futures conflicting with existing System.Web.Mvc

I downloaded MVC2 Futures and referenced it to my current MVC2 Project. However, if I want to call an HtmlHelper from MVC2 Futures I need to <%# Import Namespace="Microsoft.Web.Mvc" %>
So I decided to add it on my Web.Config:
<pages>
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="Microsoft.Web.Mvc" />
<add namespace="Xpedite.Mvc.Html" />
</namespaces>
</pages>
but, this caused me errors. Could this assemblies co-exist? If yes, How?
I'm pretty sure you need the MVC3 Futures pack:
http://aspnet.codeplex.com/releases/view/54306
The MVC2 Future was made to work against MVC1. I had the same issue and upgrading to the next futures release solved it for me.

HtmlHelper not recognized in runtime

I am developing a Web app that is based on ASP.NET 3.5, and i added some page from ASP.NET MVC, everything is ok, until i use the "HTML" helper class, then the page is not being able be render, because this is not recognized.
For Example : Html.BeginForm() => this is not recognize as a method
But if i used "System.Web.Mvc.Html.FormExtensions.BeginForm", which is a extension method itself, it work fine.
Environment : ASP.NET MVC 2 and ASP.NET 3.5
Anyone experiencing this problem?
Thanks.
Do you have the System.Web.Mvc.Html namespace included in web.config's page assemblies list? I.e.:
<pages>
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
**<add namespace="System.Web.Mvc.Html" />**
<add namespace="System.Web.Routing" />
</namespaces>
</pages>

How do I configure extensionless URLs with the Visual Web Development server?

I'm using Visual Studios' built-in ASP.NET Development Server (VWD) to test my web site during development.
I would like this ASP.NET web site to use extensionless URLs (pages don't require the aspx extension). Ordinarily I would configure a custom 404 in IIS that directs to an ASPX page. How would I do this with VWD?
P.S. This is not an ASP.NET MVC web site.
Here is an example of a Web.Config using UrlRewritingNet. Doing this will allow you to do extensionless Rewriting without having to write any HttpModule or anything like that.
(full article here)
Note: this requires IIS7 as it is using the system.webServer section of the web.config.
<configSections>
<section name="urlrewritingnet"
restartOnExternalChanges="true"
requirePermission="false"
type="UrlRewritingNet.Configuration.UrlRewriteSection, UrlRewritingNet.UrlRewriter" />
</configSections>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter" />
</modules>
</system.webServer>
<urlrewritingnet rewriteOnlyVirtualUrls="true"
contextItemsPrefix="QueryString"
xmlns="http://www.urlrewriting.net/schemas/config/2006/07">
<rewrites>
<!--Enable HTM(L) Extensions-->
<add name="pageHTML"
virtualUrl="^~/(.+).htm(.*)"
redirectMode="Permanent"
rewriteUrlParameter="ExcludeFromClientQueryString"
destinationUrl="~/$1.aspx"
ignoreCase="true" />
<!--Fix the WebResource JS Error-->
<add name="WebResourceFix"
virtualUrl="^~/WebResource.axd(.*)"
rewriteUrlParameter="IncludeQueryStringForRewrite"
destinationUrl="~/WebResource.axd$1"
ignoreCase="true"/>
<!--Fix the ScriptResource JS Error-->
<add name="ScriptResource"
virtualUrl="^~/ScriptResource.axd(.*)"
rewriteUrlParameter="IncludeQueryStringForRewrite"
destinationUrl="~/ScriptResource.axd$1"
ignoreCase="true"/>
<!--Allow Extensionless Page Extensions-->
<add name="pageExtensionless"
virtualUrl="^~/(.+)$"
redirectMode="Permanent"
rewriteUrlParameter="ExcludeFromClientQueryString"
destinationUrl="~/$1.aspx"
ignoreCase="true" />
</rewrites>
</urlrewritingnet>
There's nothing special you need to do. Just remove the .aspx extension from the ASPX page file and it should work fine with VWD. The Visual Studio designer will probably complain that there's no build provider registered for the extension '', but you can just ignore it. Then you can reference the page without extension:
http://localhost:2181/Default
<%# Page Language="C#"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
Hello World
</div>
</form>
</body>
</html>
If you are trying to get something like http://localhost:3000/value to go to http://localhost:3000/page.aspx?tag=value then you can use an HttpModule, which is also a good alternative to a 404 redirect. I used to do the same thing too.
I posted some example code in a previous question.
All you need to do is add the module in two different places within your web.config...
<system.web>
<pages theme="Default" />
<httpModules>
<add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter" />
</httpModules>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="UrlRewriteModule"/>
<add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter" />
</modules>
</system.webServer>
The first one is to add it to your httpModules with will work in your VS Dev environment, and the second one will for IIS7

Resources