How to change WebGrid action for getting data (.NET MVC3)

后端 未结 4 901
无人及你
无人及你 2021-02-10 00:28

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

public ActionResult Index()
{
    return View();
}
public ActionResult GetUserList(int? pag         


        
4条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-10 00:50

    Your conclusion isn't right. You just need to wrap your webgrid in a Get form:

    using (Html.BeginForm("GetUserList", "ThingaMaBob", System.Web.Mvc.FormMethod.Get))
    {
     var grid = new WebGrid(
    ...
    ));
    
        Html.Hidden(grid.SortFieldName, grid.SortColumn);
        Html.Hidden(grid.SortDirectionFieldName, grid.SortDirection == SortDirection.Ascending ? "ASC" : "DESC");
    }
    

    The hiddens are so that the sort dir and sort field end up in parseable form in the querystring. You end up with urls like localhost/ThingaMaBob/GetUserList?someotherfields=whatever=&sort=city&sortdir=ASC

提交回复
热议问题