This question is locked. New answers and comments are not allowed.
Did you ever wonder how you could achieve ins erver binding mode that filter and sorting settings for the grid are retained across edit operations? Here is my solution for it:
Then instead of
you do
I hope this is useful to someone.
Please feel free to make suggestions on how to make this better.
public static class MvcHelpers { public static void ForEach<T>(this IEnumerable<T> items, Action<T> action) { foreach (T item in items) { action(item); } } private static NameValueCollection ExtractGridParameters(NameValueCollection aParams) { Contract.Requires(aParams != null); var lRelevantKeys = aParams.AllKeys .Where(i => i.EndsWith("-filter") || i.EndsWith("-page") || i.EndsWith("-orderBy")); var result = new NameValueCollection(); lRelevantKeys.ForEach(i => result.Add(i, aParams[i])); return result; } public static RedirectToRouteResult WithGridSettings(this RedirectToRouteResult result, NameValueCollection aParams) { ExtractGridParameters(aParams).AllKeys.ForEach(e => result.RouteValues.Add(e, aParams[e])); return result; } }Then instead of
return RedirectToAction("Index");you do
RedirectToAction("Index").WithGridSettings(Request.QueryString);I hope this is useful to someone.
Please feel free to make suggestions on how to make this better.