We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

MVC Grid return other control values in ajax postback

I want to have an MVC grid with some controls on the top that the user can use to filter the data. For example, I might have a checkbox on top of the grid saying: "Show only Rows of Type X"
After the first page is displayed and the user clicks to view the next row (or sorts, filters,etc.) I need the post to my controller to include the state of the controls like the checkbox as these will need to be part of the query used to get the next page.

How can I include them in the info posted back? If I just wrap the controls and the grid in an Html.BeginForm in my view, will this work?


2 Replies

SH Steven Hunt September 8, 2011 07:09 PM UTC

Just realized there is a separate forum for MVC. Moved it there....



SN Sridhar N Syncfusion Team September 12, 2011 03:00 PM UTC

Hi Stevan,

Thanks for your interest in Syncfusion Products.

Your requirement can be achieved by handling OnActionBegin event and set the control value to grid arguments. Please refer the below code snippet.

[View]

<%using (Html.BeginForm("Index","Home"))
{%>
<%=Html.CheckBox("Check",true) %>

<% =Html.Syncfusion().Grid<object>("Grid2")
.Datasource((IEnumerable)ViewData["Griddata2"])
.EnablePaging()
.EnableSorting()
.AutoFormat(Skins.Sandune).EnableGrouping().ClientSideEvents(events => { events.OnActionBegin("OnActionBegin"); })
%>

<% } %>



[Controller]

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(PagingParams args, bool Check)
{
//Check is the checkbox state
var data1 = new NorthwindDataContext().Employees.Take(50).ToList();
ViewData["Griddata2"] = data1;
return data1.GridActions();
}



[Javascript]

function OnActionBegin(sender, args)
{
//Check box state
var check = $('#Check')[0].checked;
args.data["Check"] = check;
}


For your convenience, we have created sample and the same can be downloaded from the following link.

GridPartial1085540280.zip

Please let me know if you have any other questions or concerns.

Regards,
Sridhar.N



Loader.
Live Chat Icon For mobile
Up arrow icon