Telerik的ASP.NET AJAX radgrid控件的MVC和ViewState的? [英] Telerik ASP.NET Ajax RadGrid in MVC and ViewState?

查看:153
本文介绍了Telerik的ASP.NET AJAX radgrid控件的MVC和ViewState的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是正确的,在MVC的ASP.NET AJAX控件。我知道,我知道,有Telerik的MVC控制,但Telerik的MVC电网没有我需要的一切,所以我使用ASP.NET AJAX控件死心塌地。

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.

不管怎么说,我有radgrid控件和运行伟大。当我使所有的花里胡哨,如分页,排序,过滤等。它看起来像它在eventargument变量后放GROUP BY /过滤/排序数据将出现问题:

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

在我的情况下,当页面重新加载,没有什么变化。有什么我应该使这个在MVC工作?我按照指示在 http://www.telerik.com /help/aspnet-ajax/mvc-getting-started.html 但这不上来。在previous URL中的例子并不拥有所有花俏,所以我假设有我需要得到这个工作的额外步骤。

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.

谢谢!

推荐答案

我是能够找到解决这一点,虽然这不是很pretty。它使用一个小的反射和硬codeD转换成对象的树。希望这将是任何人都需要的ViewState在MVC一个很好的起点。

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.

基本上,它涉及到反序列化的ViewState成一个对象,然后使用反射,调用控件的LoadViewState与对象的树分支,在右侧。

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);
    }

看到这个职位的详细信息:<一href=\"http://stackoverflow.com/questions/7435738/supporting-viewstate-in-an-mvc-viewusercontrol\">Supporting ViewState的在MVC ViewUserControl

这篇关于Telerik的ASP.NET AJAX radgrid控件的MVC和ViewState的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆