My controller method with WebApi2
[HttpGet]
public IEnumerable<Products> GetProducts(ProductSearchCriteria searchCriteria)
{
//searchCriteria is always null here!!! Why?
return db.Instance.LoadProducts(searchCriteria);
}
My search criteria class
public class ProductSearchCriteria
{
private int id;
private string name;
private DateTime createdOn;
[JsonProperty]
public string Name
{
get { return this.name; }
set { this.name = value; }
}
[JsonProperty]
public DateTime CreatedOn
{
get { return this.createdOn; }
set { this.createdOn = value; }
}
[JsonProperty]
public int ID
{
get { return this.id; }
set { this.id = value; }
}
}
My script in the html page
<script>
$("#btnTest").on("click", function () {
var searchCriteria = {};
searchCriteria.ID = 0;
searchCriteria.Name = "";
//searchCriteria.CreatedOn = "";
var url = "http://localhost:8080/api/products"
$.getJSON(url, searchCriteria).done(processResponse);
});
function processResponse(response){
}
</script>
I reach my controller method (debug mode) but the ProductSearchCriteria searchCriteria parameter is always null. How can I send my JSON object using get method with JQuery and WebApi2?