So I am writing some Asp.Net WebApi code to hook with old C# back-end code where there is no model class used. (Pure dataTable returned from DataAccess, Crazy right? I know)

Following is the code I put on the Server side.

 public IHttpActionResult GetProduct(int campaignID, int productID)
    {
        var so = new SearchOptions(campaignID)
        {
            ProductID = productID
        };

        var result = SearchManager.Search(so);
        if (result == null || result.Rows.Count == 0)
            return NotFound();
        return Ok(result.Rows[0]);

    }

I am expecting to have the response like this:

{
Field1: "field1",
Field2: "field2",
...
}

But Actually I am having this:

{
  "rowError": "",
  "rowState": 2,
  "table": [
    {
      Field1 : "field1",
      Field2 : "field2",
      ...
    }
  ],
  "itemArray": ["field1","field2"],
  "hasErrors": false
}

I don't want all these rowError, rowState...etc

If I am doing this on the server side:

public IHttpActionResult GetProduct(int campaignID, int productID)
        {
            var so = new SearchOptions(campaignID)
            {
                ProductID = productID
            };

            var result = SearchManager.Search(so);
            if (result == null || result.Rows.Count == 0)
                return NotFound();
            return Ok(result);

        }

I am receiving this:

[{Field1: "field1", Field2: "field2"..}]

which is unfortunately rejected by ngResource get method since it is an array rather than a single Json Object.

What should I do? If I just want to return a single dataRow as a Json string.

Thanks

Related posts

Recent Viewed