2

data.js

My method call:

var dateCollection = ["2014-12-12,"2013-12-12"];
getCompanyData(1,dateCollection);

var getCompanyData = function (Id, stmtDate)
        {
            var promise = $http.get(baseUrl() + "api/Search/CompanyData/" + Id + "/" + stmtDate)
                .success(function (data, status, headers, config) {

                    return data;
                })
                .error(function (data, status, headers, config) {
                    return data;
                });

            return promise;

        }

SearchController.cs

[ActionName("CompanyData")]
[HttpGet]
public async Task<IHttpActionResult> GetCompanyData(string Id , string[] stmtDate)
{
}

I need to send array of stmtDate (which contains strings) to a GetCompanyData web API controller.

My WebApiConfig.cs has following route:

config.Routes.MapHttpRoute(
                name: "ApiByMultiParams",
                routeTemplate: "api/{controller}/{action}/{Id}/{stmtDate}"
            );

The problem, is while trying to pass an array of data, when it hits the web API controller method: GetCompanyData, stmtDate doesn't receive the array and it is coming up as null. Also iI would appreciate any suggestions on how to convert a datetime which is in the format: 2014-12-12 00:00:00 to 2014-12-12 (in AngularJS).

1 Answer 1

1

you are trying add array at end of url string. Send date as parametr

var getCompanyData = function (Id, stmtDate) {
    var promise = $http.get(baseUrl() + "api/Search/CompanyData/" + Id, {
            params: {
                date: stmtDate
            }
        }
    ).success(function (data, status, headers, config) {

            return data;
        })
        .error(function (data, status, headers, config) {
            return data;
        });

    return promise;

}
Sign up to request clarification or add additional context in comments.

2 Comments

i tried this but i got 404 error.should i modify webapiconfig.cs accordingly ,if i want to give this way?
how would it take my second parameter stmtDate if i give only Id in the webapiconfig?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.