I am trying to call a ASP.NET WebAPI method and pass it a serialized JavaScript object over a GET request similar to a $.ajax
POST request. It is working fine except for when the JavaScript object has a null value for Networks, then it sends it in the URL like /api/airings/get-airings?networks=
and the server is showing the string[] as having a single item with a value of null! If I remove the network=
it shows up as null on the server as I would expect.
So, it appears that people requested tickets in jQuery regarding this behavior, but I want to know what I can do without using a plugin or rewriting the $.param logic or messing with WebAPI ModelBinder.
http://bugs.jquery.com/ticket/8653
http://bugs.jquery.com/ticket/1814
public class ApiGetAiringsRequest
{
public DateTime? DateStart { get; set; }
public DateTime? DateFinish { get; set; }
public string[] Networks { get; set; }
}
public HttpResponseMessage GetAirings([FromUri] ApiGetAiringsRequest request )
...
document.location.href = "/api/airings/get-airings?" + $.param(request);