Search code examples
c#asp.net-mvchttp-postasp.net-mvc-5querystringparameter

Query String Parameters to MVC Controller ActionResult using POST


I have following query string parameters method is POST using anularjs as

var req = {
           method: 'POST',
          url: "/UserGrid",
           params: {
                        rows : 15,
                        page: 1,
                        sidx : "ID",
                        sord: "DESC",
                        _search: true,
                        filters: {"groupOp":"AND","rules":[{"field":"username","op":"cn","data":"suz"}]}
                    }, 
                };
$http(req).success(function(data, status, headers, config){
     console.log(data)
 });

_search:true
filters:{"groupOp":"AND","rules":[{"field":"username","op":"cn","data":"suz"}]}
page:1
rows:3
sidx:ID
sord:desc

I have following method

 [HttpPost]
    public ActionResult UserGrid(bool _search, GridFilterHelper filters, int page, int rows, string sidx, string sord)
    {
         GridFilterHelper mFilters = filters;
         return Json(mFilters);
    }

filters in the above code are null. Can someone help me how can I pass filters to this action method.

here is the grifilterHelper class

public class GridFilterHelper
    {
        public string groupOp { get; set; }
        public List<Rules> rules { get; set; }
    }

    public class Rules
    {
        public string field { get; set; }
        public string op { get; set; }
        public string data { get; set; }
    }

Solution

  • The query string parameter filters was string not an object. So I change it to Json from string.