This question is locked. New answers and comments are not allowed.
Hello,
I have a custom filtering solution I've built for the MVC Grid, which works wonderfully, except for the fact that I can't get the filter data added into the post when using AJAX().Select binding.
Here is the JavaScript I registered with onDataBinding.
I've debugged this code and args.data is being set to filter, but for some reason, that data isn't added to the post (I verified this with Fiddler) and is therefore not available to my action.
Here's my controller code.
The string "filter" in this action is always null. I've tested that the action works by mocking up a post request using Fiddler where I added the proper filter string and it's captured just fine by the action.
Thanks!
Nathan
I have a custom filtering solution I've built for the MVC Grid, which works wonderfully, except for the fact that I can't get the filter data added into the post when using AJAX().Select binding.
Here is the JavaScript I registered with onDataBinding.
function dataBinding(args) {
var filter = ""; var filterableColumns = $("[prism-name^=filter-column]"); for(var i = 0; i < filterableColumns.length; i++) { if(filterableColumns[i].value != "") { if(filter != "") { filter += "~"; } filter += filterableColumns[i].getAttribute('prism-name').replace("filter-column-", "") + "|" + filterableColumns[i].value; } document.cookie = createCookie(window.location.pathname + "/" + filterableColumns[i].getAttribute('prism-name'), filterableColumns[i].value); } args.data = filter; }
I've debugged this code and args.data is being set to filter, but for some reason, that data isn't added to the post (I verified this with Fiddler) and is therefore not available to my action.
Here's my controller code.
[GridAction] public ActionResult _Filter(string filter) { if (filter == null) { filter = string.Empty; } var project = filter.DeserializeFilterString<Project>(); return View(new GridModel<Project>(db.Projects.Where(p => (string.IsNullOrEmpty(project.ProjectType) || p.ProjectType.Contains(project.ProjectType))).ToList())); }The string "filter" in this action is always null. I've tested that the action works by mocking up a post request using Fiddler where I added the proper filter string and it's captured just fine by the action.
Thanks!
Nathan