DevExpress MVCxGridView in Orchard module - Callbacks don't work

Topics: Customizing Orchard, General, Troubleshooting, Writing modules
Jun 13, 2012 at 1:49 PM

Hello,

We want to use Orchard for a website. We are creating a custom module/widget for that cms and in that module we want to use a GridView from DevExpress to show data. We got most of it working, but we can't get callbacks to work. With that i mean things like navigating through pages, sorting rows and moving columns.

If we look in the console we can see that the javascript and ajax callbacks are never executed, we can't figure out why that is so. I have found some topics on the DevExpress site and this site about using DevExpress with Orchard, but i couldn't find anything usefull (for my case) in those. We also noticed that the methods of our controller are never called, but cannot figure out why not.

I have made an example project. The file is 40MB because i added the entire cms to itwith example daabase, including our module. The module is called GridViewTest You can find the source here:http://www.obec.nl/download/Orchard-DevExpress.zip.

I hope someone can help me figure out what the problem is, because i'd really like to use DevExpress in Orchard.

Jun 19, 2012 at 3:45 PM

Hello,

I have finally found a solution. It turned out to be a pretty simple one (like usual) and i want to share it here, in case other people want to use DevExpress with Orchard:
In your Orchard module, you have to create a Routes.cs file (in the root of the module). There you have to add this:

using System.Collections.Generic;
using System.Web.Mvc;
using System.Web.Routing;
using Orchard.Mvc.Routes;

namespace CentralStationDataView
{
    public class Routes : IRouteProvider
    {
        public void GetRoutes(ICollection<RouteDescriptor> routes)
        {
            foreach (var routeDescriptor in this.GetRoutes())
            {
                routes.Add(routeDescriptor);
            }
        }

        public IEnumerable<RouteDescriptor> GetRoutes()
        {
            return new[] 
            {
                new RouteDescriptor 
                {
                    Priority = 5,
                    Route = new Route(
                        "AreaName",
                        new RouteValueDictionary
                        {
                            { "area", "AreaName" },
                            { "controller", "ControllerName" },
                            { "action", "ActionName" }
                        },
                        new RouteValueDictionary(),
                        new RouteValueDictionary 
                        {
                            { "area", "AreaName" }
                        },
                        new MvcRouteHandler())
                }
            };
        }
    }
}

You can make the AreaName up as you like, it doesn't matter (as far as i know) what you call it. Make sure that you don't add the "Controller" suffix to the ControllerName.Then, in your GridView settings you have to add this:settings.CallbackRouteValues = new { area = "AreaName", Controller = "ControllerName", Action = "ViewDataPartial" };These values have to all be exactly the same as the values in the Routes.cs file. The "area" property was critical for me, i already had the Routes.cs file and everything, but i didn;t add the area property to the CallbackRouteValues.


The second part of the solution is that you have to make a partial view with only and i stress, only, the GridView inside it. So no scripts, no extra html elements, no text, nothing.