1

I'm using jQuery Datatable and server side proccessing as data source in my ASP.Net MVC application. I need to apply search term in my query but I don't know how to catch it.

here is short version of my controller :

public JsonResult Index(POFilter m) {
   return Json(new {
      data = data,
      ...
   })
}

POFilter.cs

public class POFilter
{
    public int start { get; set; }
    public int length { get; set; }
    public int draw { get; set; }
    public List<DT_Order> order { get; set; }
    public string[] search { get; set; }

    public POFilter()
    {
        start = 0;
        length = 10;
        draw = 1;
    }
}

public class DT_Order
{
    public int column { get; set; }
    public string dir { get; set; }
}

but for some reason the search property is always null. you can see the parameters which are passed by jquery datatable:

order[0][column]:0
order[0][dir]:desc
start:0
length:10
search[value]:my search term
search[regex]:false

how can I get my search term from passed parameters?

2
  • order is also null? Commented Apr 22, 2015 at 6:36
  • @adricadar no it's not null itself but order[0].column and order[0].dir have wrong values. anyway, I found the answer. I should use m.search = Request["search[value]"] or in general Request[key] Commented Apr 22, 2015 at 6:51

3 Answers 3

1

Use datatables.mvc5 nuget package to get typed modelbinder:

public JsonResult GetData([ModelBinder(typeof(DataTablesBinder))] IDataTablesRequest requestModel)
{
    // requestModel.Start..
    // requestModel.Length..
    // requestModel.Columns..
}
Sign up to request clarification or add additional context in comments.

Comments

1

I'm using an object to hold the search result. Instead of using:

public string[] search { get; set; }

I use:

public DataTableSearch Search { get; set; }

Where DataTableSearch is defined as:

public class DataTableSearch
{
    public string Value { get; set; }
    public string Regex { get; set; }
}

Let me know if that doesn't fix your issue (if you're still having an issue).

Comments

0

Take a look at this project, it is a MVC / Jquery datatable implementation made by a friend. I use this in almost all of my projects

https://github.com/amoerie/generic-datatables

its a bit hard to implement, but once it is in place, its easy to work with

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.