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

Additional Refresh function

Dear Sir,

When developing web application, we have a form to enter selection criteria, then click the Query button on form to submit the criteria, in MVC mode, another action will handle this request and regenerate the content of grid,

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult ShowGridActionX(string objNum)
{
DataModel model = new DataModel();
IList result = model.GetData(objNum);
return result.GridActions();
}

How do I simulate the post to this action and refresh the content of grid?

3 Replies

BK Balaji K Syncfusion Team July 28, 2009 03:06 PM UTC

Hi Mac,

Thank you for using Syncfusion products.

We can use the same form post in MVC.Please find the code snippet illustrating that.

[ASPX]
<% using (Html.BeginForm("ShowGridActionX","ControllerName")) { %>
<%=Html.TextBox("objNum") %>
<%=Html.Grid("Grid1")%>


<% } %>

[Controller]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult ShowGridActionX(string objNum)
{
DataModel model = new DataModel();
IList result = model.GetData(objNum);
return result.GridActions();
}

Let us know if you have any issues.

Regards,
Balaji.


ML mac lee July 29, 2009 10:02 AM UTC

Not really.

I hope,
1. using Ajax when post back.
2. get the data entered in the form as parameter for controller.

If the grid has additional functionality to post back data in the form and refresh function, it is more usefull in real world application programming; otherwise, the sorting/paging/grouping function cannot working properly.

I've wrote a Javascript to do refrshing thru simulate the sorting postback when click a button on the form:

//var formID = "#QueryForm";
//var gridID = "ModifyUserGrid";

var firstField;
var sorting = "Ascending";

if ($(formID).valid() == false) {
return false; // do nothing
}

var grid = $find(gridID);
var col = grid.get_columns();
firstField = col[0].MappingName;

var PagingParams = {
RequestType: 2,
SortColumn: [firstField],
SortDirection: [sorting],
StartIndex: 0,
PageSize: 0, //grid.get_PageSize(),
ID: grid.get_id(),
SkinName: grid.get_SkinName()
};
var requestArgs = Sys.Serialization.JavaScriptSerializer.serialize(PagingParams);

var PagingParams = {
GridRequestParams: requestArgs,
ClientObject: grid.getClientObject(),
RequestType: 2,
SortColumn: [firstField],
SortDirection: [sorting],
StartIndex: 0,
PageSize: 0, //grid.get_PageSize(),
ID: grid.get_id(),
SkinName: grid.get_SkinName()
}

var f2 = $(formID).formToArray();
// Merge form data into PagingParams
var p1 = $.param(PagingParams);
var p2 = $.param(f2);
p1 = p1 + (p2 ? "&" : "") + p2;
grid._sendHtmlActionRequest(p1, "sorting", grid.get_ServerModePagingSortingMapper());

this is what I can do to bind data for grid when postback, but lost paging/sorting/grouping functions of grid cause no form data was posted back to controller.



BK Balaji K Syncfusion Team July 30, 2009 06:49 AM UTC

Hi Mac

Please find the code snippet to refresh the grid's content.

Live Chat Icon For mobile
Up arrow icon