ASP.NET Ajax Controls in ASP.NET MVC

by ASP.NET AJAX Team | Comments 11

The Q3 2008 release is now out and I am glad to inform you that RadScriptManager provides support for ASP.NET MVC view and master pages. What this means is that RadControls for ASP.NET Ajax can be used in ASP.NET MVC. We have tested with the ASP.NET MVC Beta 1 release.

Using RadControls for ASP.NET Ajax in ASP.NET MVC View Pages

1. Add an instance of RadScriptManager to your view page (or master page). Make sure the required HTTP handlers are properly registered (can be done from the smart tag in design time).

2. Add a control to your view page or master page. The following controls require further configuration in order to properly work in ASP.NET MVC:

  • RadEditor
    • The dialog HTTP handler’s extension should be changed to "axd":
      Before:
      <add path="Telerik.Web.UI.DialogHandler.aspx" ... /> 
      After:
      <add path="Telerik.Web.UI.DialogHandler.axd" ... />
    • The DialogHandler property of RadEditor should be set to
      "~/ Telerik.Web.UI.DialogHandler.axd":
      <telerik:RadEditor runat="server" ID="RadEditor1" DialogHandlerUrl="~/Telerik.Web.UI.DialogHandler.axd" /> 
    • RadEditor should be placed inside a form tag.
  • RadUpload
    • The progress manager HTTP handler’s extension should be changed to "axd":
      Before:
      <add path="Telerik.RadUploadProgressHandler.ashx" ... />
      After:
      <add path="Telerik.RadUploadProgressHandler.axd" ... />
    • Set the AjaxUrl property of RadProgressManager to "~/Telerik.RadUploadProgressHandler.axd":
      <telerik:RadProgressManager runat="server" ID="RadProgressManager1" AjaxUrl="~/Telerik.RadUploadProgressHandler.axd"/> 
    • RadUpload should be placed inside a form tag
  • RadSpell
    • The dialog HTTP handler’s extension should be changed to "axd":
      Before:
      <add path="Telerik.Web.UI.DialogHandler.aspx" ... />
      After:
      <add path="Telerik.Web.UI.DialogHandler.axd" ... /> 
    • The HandlerUrl property of RadEditor should be set to "~/ Telerik.Web.UI.DialogHandler.axd":

Samples

Using navigation controls and linking to actions

This approach is useful when you need a navigation control (RadTreeView, RadTabStrip, RadPanelBar, RadMenu, RadToolBar) to link to actions.

<% RadTreeView1.DataBind() %> 

<telerik:RadTreeView runat="server" ID="RadTreeView1">
<Nodes>
<telerik:RadTreeNode NavigateUrl='<%# Url.Action("Index")%>' Text="Index" />
<telerik:RadTreeNode NavigateUrl='<%# Url.Action("Home")%>' Text="Home" />
</Nodes>
</telerik:RadTreeView>

DataBinding RadGrid

<% 
RadGrid1.DataSource = ViewData["MyBusinessObjectCollection"];
RadGrid1.DataBind();
%>

<telerik:RadGrid runat="server" ID="RadGrid1" />

For a more advanced example check this blog post. You can also go and check the live demo.

Uploading Files with RadUpload

View:
<% using (Html.BeginForm("Upload", "Home")){%> 

<telerik:RadUpload runat="server" ID="RadUpload1" ></telerik:RadUpload>
<telerik:RadProgressManager runat="server" ID="RadProgressManager1" AjaxUrl="~/Telerik.RadUploadProgressHandler.axd"/>
<telerik:RadProgressArea runat="server" ID="RadProgressArea1"/>

<input type="submit" value="Upload" />

<%} %>
Controller:
public ActionResult Upload() 
{
if (Request.Files.Count > 0)
{
Request.Files[0].SaveAs("path_to_file");
}
return View("Index");
}

Known Limitations

RadAjaxManager, RadAjaxPanel, postbacks and ViewState are not supported

By default ASP.NET view pages don’t have server form tag (<form runat=”server”>) which is required for ViewState and postbacks support. Partial rendering is also not supported by ASP.NET MVC and as a result RadAjaxManager and RadAjax panel are not working.

RadScheduler does not support ASP.NET MVC at the time being.

RadScheduler relies on postbacks (or ajax requests) in order to insert, update, delete appointments. Support for ASP.NET MVC will be implemented in the upcoming Q1 2009 release.

RadGrid’s built-in insert, update, delete, sort, group are not supported

All those features rely on postbacks by default and as such are not supported in ASP.NET MVC. This blog post describes how to work around this problem.

Skin and base CSS files should be registered by hand when using the PartialView method

Alternatively you can use RadStyleSheetManager in the user control used in PartialView.

Updates via the built-in ASP.NET Ajax support are not supported

The HTML of the controls is successfully updated however JavaScript is not executed by the built-in ASP.NET MVC Ajax implementation. We would provide a workaround in the future.

Only the ASP.NET rendering engine is supported

This stems from the fact that RadControls for ASP.NET Ajax depend on the ASP.NET Page and control lifecycle.

Future

A full-blown ASP.NET MVC application built on top of RadControls for ASP.NET Ajax and Telerik OpenAccess is already in the works. I will blog when it is ready.

About the author

Iana Tsolova

Iana Tsolova

is Program Manager of Telerik’s ASP.NET AJAX division. She joined the company back in the beginning of 2008 as a Support Officer and has since occupied various positions at Telerik, including Senior Support Officer, Team Lead at one of the ASP.NET AJAX teams and Technical Support Director. Iana’s main interests are web development, reading articles related to geography, wild nature and latest renewable energy technologies.

11 Comments

King Wilder
This is a welcome bit of news! I will surely be trying this out on my next MVC project.
paolo bettoni
I have dropped the RadMenu on a bare page with nothing else on it, and it shows up in the browser without skin.

I have tried swapping RadMenu for RadToolBar, and ToolBar shows without any problem...

can you help?

Thanks
paolo bettoni
My post continued...

Sorry, I should have mentioned the following:

- I am working on ASP.NET MVC
- I am getting the " 'sys' is undefined " javascript error in the browser...

Thanks
Boris R.
Is there a hope we shall see soon RadControls for ASP.NET Ajax flying on the Azure cloud?
ASP.NET MVC is supposed to be dominant framework for Azure web apps.

Thanks
Adam Cooper
Hi Atanas,

We're trying to incorporate a RadEditor control into a new ASP.NET MVC application and, although we followed the steps you outlined in your post, we're still having some trouble. At runtime we're getting a javascript error that appears to be related to ASP.NET AJAX.

Can you provide some more information about the dependencies that are required? That is, what ASP.NET AJAX js files need to be included, etc. Even better would be a complete example of RadEditor running in MVC.

Thanks,
Adam Cooper
Stuart Cullinan
Great news about MVC support. Atanas, do you know if the ReportViewer control will work with MVC framework?
Ahmed
i need to try it
James
Using the sample code above to for the RADUpload control with ASP.Net MVC works great on a view page but when I put it in a user control and call Html.RenderPartial I get an error.  Any ideas why this wouldn't work?

The error I get..

An exception of type 'System.Web.HttpUnhandledException' occurred in System.Web.dll but was not handled in user code.

 

Quan Nguyen
I am trying to use RadControls Q1 2009 in ASP.NET MVC applications.May I ask about some samples with RadTextBox and RadGrid~27s data binding~3f~3cbr /~3e ~3cbr /~3e I~27ve just found that most samples are using Ajax.ActionLink ~28instead of RadControl~27s event~29 and I don~27t see much~3a~22RadControl Q1 2009 is support MVC~22 - in Vladimir Enchev~27s Grid Example still used Ajax.ActionLink for Select~2cDelete..so what~27s means ~22support MVC~22~3f~3cbr /~3e ~3cbr /~3e I~27m looking forward to seeing your explanation and sorry for my bad English ~5e~5e~3cbr /~3e
Quan Nguyen
ack~2cwhat~27s the hell with the editor~3f~3f~3cbr /~3e
almny
can you used asp.net contral

Comments

  1.    
      
      
       
  2. (optional, emails won't be shown on public pages)
  3. (optional)
Read more articles by ASP.NET AJAX Team - or - read latest articles in Developer Tools