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.
Unfortunately, activation email could not send to your email. Please try again.

MVC Grid return other control values in ajax postback

Thread ID:

Created:

Updated:

Platform:

Replies:

100821 Sep 7,2011 04:07 PM Sep 12,2011 11:00 AM ASP.NET Web Forms (Classic) 2
loading
Tags: GridGroupingControl
Steven Hunt
Asked On September 7, 2011 04:07 PM

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?


Steven Hunt
Replied On September 8, 2011 03:09 PM

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


Sridhar N [Syncfusion]
Replied On September 12, 2011 11:00 AM

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("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



CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;