Square Brackets in URL for .NET Web Service

Square Brackets in URL for .NET Web Service

newjimnewjim Posts: 3Questions: 2Answers: 0

I am using a .NET web service to receive the dataTables request. The querystring that gets sent to the web services has url-encoded square brackets in it, such as:

search%5Bvalue%5D

In my web service signature I have to enter the parameter names, for example:

public void myWebService(int draw, int start, int length)

But this doesn't work with the above, How do I receive the parameters that have square brackets in them?

Thanks

Jim

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    edited February 2015 Answer ✓

    Two options:

    1. Set the jQuery $.ajax traditional option which makes it easier to parse the parameters in .NET
    2. Use the ajax.data option to instruct DataTables to send an JSON string if you would prefer to handle that data as JSON. See the last example on that documentation page.

    Allan

  • newjimnewjim Posts: 3Questions: 2Answers: 0

    I have not figured out the first way yet but will work on it.

    Re the second way, I don't think that would work because "d" represents the built-in parameters that DataTables is sending to the serverside, but I am also sending parameters, so I don't see how I could put those into the key for "data".

    I found another way and that is to use the HttpContext object in my C# code, as shown:

    string searchValue = HttpContext.Current.Request.QueryString["search[value]"];
    int orderColumn = Convert.ToInt32(HttpContext.Current.Request.QueryString["order[0][column]"]);

    HttpContext is available when the Request object is not. In order to have it in your code, you must put this statement at the top of your C# webservice file:

    using System.Web;

    Thanks

This discussion has been closed.