1
votes

That's right, an ASP.NET Ajax control in MVC. I know I know, there are Telerik MVC controls but the Telerik MVC grid doesn't have everything I need so I'm dead set on using the ASP.NET Ajax control.

Anyways, I have the RadGrid up and running great. The problem occurs when I enable all the bells and whistles such as paging, sorting, filtering etc. It looks like it puts the group by/filter/sort data in an eventargument post variable:

__EVENTARGUMENT  FireCommand:2$RadGrid1$ctl00;GroupByColumn;Dialog

In my case, when the page reloads, nothing changes. Is there something I should enable for this to work in MVC? I have followed the instructions at http://www.telerik.com/help/aspnet-ajax/mvc-getting-started.html but this doesn't come up. The example in the previous url doesn't have all the bells and whistles, so I'm assuming there are additional steps I need to take to get this to work.

Thanks!

4
So...there exists an MVC version of this product that will do exactly what you want. But you want to hack the WebForms version and bend it to your will instead?Kirk Woll
Yeah, the MVC version doesn't have everything I need such as multiple rows selection and many other things. I really need to get the AJAX version working :/Levitikon
Perhaps this can work with the multiple row selection? (demos.telerik.com/aspnet-mvc/grid/checkboxesajax). Not sure what the many other things are, but at least a step in the right direction :)carlbergenhem
Lol, thanks @Carl B. I would consider myself salty when it comes to researching this issue. I actually spent a couple days a while back making a multiple select feature that works with the Telerik MVC grid. The problem with that is the ASP.NET Ajax version has all the stops such as Shift click, Shift up/down, and Shift drag. Plus getting multiple select to work with grouping is a nightmare. I hate recreating a cheaper version of the wheel when the BMW of wheels is sitting right in front of me with a shiny set of keys. I just need to figure out how to fit the #$%* thing in my garage.Levitikon
Ah, I see :) Never know just how much research someone has done! Also, I love the analogy ;Dcarlbergenhem

4 Answers

1
votes

There is also a Ajax Grid component developed by Stephen Halter at Microsoft, it's more simple than Telerik RadComponent but it's extensible and it offers pagin, sorting, edit, create new, etc. You can download this component from NuGet:

PM> Install-Package AjaxGridScaffolder
1
votes

One document that I always look into when dealing with integrating the RadControls for ASP.NET AJAX into ASP.NET MVC is the Limitations article, which actually specifically mentions that the built-in sorting/grouping/filtering (anything that causes a postback), is not supported in ASP.NET MVC. However, there is some hope :) It does link to this blog post which has a solution that contains some workarounds all of this, which should be helpful here. The post is a bit old, but I think you can still get something helpful out from it.

As a side-note here there might be some ninja ways to work with the Telerik MVC Grid so that you can get all your requirements and have the benefit of going native ASP.NET MVC. Perhaps post them on the Telerik forums?

1
votes

I was able to find a solution to this, though it's not very pretty. It uses a little reflection and hard coded mapping to tree of objects. Hopefully this will be a good starting point for anyone needing ViewState in MVC.

Basically it involves deserializing the ViewState into an object then using reflection, call the Control's LoadViewState with the right branch in the object's tree.

    string viewState = Request.Form["__VIEWSTATE"];

    if (!string.IsNullOrEmpty(viewState))
    {
        LosFormatter formatter = new LosFormatter();

        object savedStateObject = formatter.Deserialize(viewState);

        MethodInfo method = grid.GetType().GetMethod("LoadViewState", BindingFlags.NonPublic | BindingFlags.Instance);

        // TODO: Find a less brittle/more elegant way to isolate the appropiate viewstate object for this control
        // In the case of Telerik's RadGrid, the key wasy find the tree that had an array of 13 objects
        method.Invoke(grid, new object[] { (((((((((savedStateObject as Pair).First as Pair).Second as Pair).Second as System.Collections.ArrayList)[1] as Pair).Second as System.Collections.ArrayList)[1] as Pair).Second as System.Collections.ArrayList)[1] as Pair).First });
    }

    string eventArgument = Request.Form["__EVENTARGUMENT"];

    if (!string.IsNullOrEmpty(eventArgument))
    {
        grid.RaisePostBackEvent(eventArgument);
    }

See this post for more details: Supporting ViewState in an MVC ViewUserControl

0
votes

Check out this documentation from Telerik, it should have what you need to get this working: Integrating RadControls in ASPNET MVC