All posts

ASP.NET Ajax Controls in ASP.NET MVC

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.

Facebook DZone It! Digg It! StumbleUpon Technorati Del.icio.us NewsVine Reddit Blinklist Furl it!

Comments  7

  • 6 Nov, 11:14 AM

    This is a welcome bit of news! I will surely be trying this out on my next MVC project.

    King Wilder

  • 20 Nov, 06:41 PM

    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

  • 20 Nov, 06:45 PM

    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

    paolo bettoni

  • 22 Nov, 08:35 PM

    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

    Boris R.

  • 8 Dec, 11:14 AM

    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

    Adam Cooper

  • 12 Dec, 07:44 AM

    Great news about MVC support. Atanas, do you know if the ReportViewer control will work with MVC framework?

    Stuart Cullinan

  • 15 Dec, 08:27 AM

    i need to try it

    Ahmed

Post a comment!
  1. Formatting options
       
     
     
     
     
       
  2. Security image