如何更改的WebGrid行动获取数据(.NET MVC3) [英] How to change WebGrid action for getting data (.NET MVC3)

查看:93
本文介绍了如何更改的WebGrid行动获取数据(.NET MVC3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个局部视图呈现的WebGrid。我的控制器看起来像

I have a Partial View that renders WebGrid. My controller looks like

public ActionResult Index()
{
    return View();
}
public ActionResult GetUserList(int? page, string sort, string sortdir)
{
    var model = UserModel.getList(page,sort,sortdir);
    return PartialView("_UserList",model);
}

Index.cshtml:结果
    ....结果
   @ Html.Action(GetUserList)
结果
问题是,我每次点击网格导航或排序链接调用首页方法。我怎样才能让的WebGrid执行(在这种情况下, GetUserList )不同的操作?我敢肯定,我可以prePEND GetUserList 来使用jQuery网格中的所有链接,但我相信它应该是一个更好的办法。结果
   这也有可能是我在做什么是完全错误的,所以感谢您的建议。

Index.cshtml :
....
@Html.Action("GetUserList")

The problem is that every time I click on grid navigation or sort links it calls Index method. How can I make Webgrid to execute a different action (GetUserList in this case)? I'm sure I can prepend GetUserList to all links in grid using jquery, but I believe it should be a better way.
It's also possible that what I'm doing is completely wrong, so thanks for your suggestions.

推荐答案

很多胡闹周围和挖掘(甚至用的WebGrid的源$ C ​​$ C反射摆弄)之后,我得出的结论,与的WebGrid,你不能控制/改变标题链接操作。

After lot of monkeying around and digging (and even fiddling with Reflector with WebGrid's source code), I came to the conclusion that with WebGrid, you cannot control/change the Header link action.

要创建头链接URL,路径是从 HttpContext.Request.Path 拍摄,所以没有办法来定制它指向一个不同的路线。

To create the header link URL, the path is taken from HttpContext.Request.Path, so there is no way to customize it to point to a different route.

一个的非常丑陋的黑客的将是进军到jQuery的阿贾克斯的事件(因为标题链接使用jQuery.load排序),并覆盖网址:

One very ugly hack would be to tap into to jQuery Ajax's events (since the header link uses jQuery.load to sort) and overwrite the URL:

<a href="#" onclick="$('#myGrid').load('/?sort=AlbumId&amp;sortdir=ASC&amp;__=634486582282704242 #myGrid');">Album Id</a>

更好的解决方案将是使用

Better solution would be to use:


  • Telerik的网格,它可以让您指定定制路由的,也渲染提供了更大的灵活性您布局

  • MvcContrib电网(不知道这是否可以修改标题链接,但绝对提供了比的WebGrid更多的灵活性)

  • Telerik Grid which lets you specify custom routes and also offers much more flexibility in rendering your layout
  • or MvcContrib Grid (not sure if this lets you modify header links but definitely offers more flexibility than WebGrid)

这篇关于如何更改的WebGrid行动获取数据(.NET MVC3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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