Skip to main content
Provided generated URLs
Source Link
jokul
  • 1.3k
  • 1
  • 16
  • 39

I want to pass a collection of strings to an API endpoint:

[HttpGet]
public DashboardSectionViewModel GetDashboard(
    DateTime lowerBound,
    DateTime upperBound,
    [FromUri] List<string> excludedStores = null,
    [FromUri] List<string> excludedItems = null)
{
    //Code
}

Here is where I make the call:

$.ajax({
    url: App.Services.updateUrl + src.updateUrl,
    type: "GET",
    data: {
        lowerBound: self.slideFilter.lowerBoundDisplay(),
        upperBound: self.slideFilter.upperBoundDisplay(),
        excludedStores: self.storeFilter.excludedStores(),
        excludedItems: self.experienceFilter.excludedItems()
    }
});

It works just fine when the two collection items are not parameters and are not passed by the AJAX request. It didn't work when I initially used IEnumerable<string> and changing to List<string> did not work either. Do I need to set a custom route for this to work? Will the interpreter get DateTime but not IEnumerable<T>?

EDIT: Here is the URL being generated with empty collections passed:

(header)/api/ContentApi/GetDashboard?lowerBound=10-12&upperBound=10-23

Here is the URL being generated with some collection items passed:

(header)/api/ContentApi/GetDashboard?lowerBound=10-10&upperBound=10-23&excludedStores%5B%5D=hello&excludedStores%5B%5D=world&excludedExperiences%5B%5D=hello&excludedExperiences%5B%5D=world

I think this is a serialization issue, but I'm not certain.

I want to pass a collection of strings to an API endpoint:

[HttpGet]
public DashboardSectionViewModel GetDashboard(
    DateTime lowerBound,
    DateTime upperBound,
    [FromUri] List<string> excludedStores = null,
    [FromUri] List<string> excludedItems = null)
{
    //Code
}

Here is where I make the call:

$.ajax({
    url: App.Services.updateUrl + src.updateUrl,
    type: "GET",
    data: {
        lowerBound: self.slideFilter.lowerBoundDisplay(),
        upperBound: self.slideFilter.upperBoundDisplay(),
        excludedStores: self.storeFilter.excludedStores(),
        excludedItems: self.experienceFilter.excludedItems()
    }
});

It works just fine when the two collection items are not parameters and are not passed by the AJAX request. It didn't work when I initially used IEnumerable<string> and changing to List<string> did not work either. Do I need to set a custom route for this to work? Will the interpreter get DateTime but not IEnumerable<T>?

I want to pass a collection of strings to an API endpoint:

[HttpGet]
public DashboardSectionViewModel GetDashboard(
    DateTime lowerBound,
    DateTime upperBound,
    [FromUri] List<string> excludedStores = null,
    [FromUri] List<string> excludedItems = null)
{
    //Code
}

Here is where I make the call:

$.ajax({
    url: App.Services.updateUrl + src.updateUrl,
    type: "GET",
    data: {
        lowerBound: self.slideFilter.lowerBoundDisplay(),
        upperBound: self.slideFilter.upperBoundDisplay(),
        excludedStores: self.storeFilter.excludedStores(),
        excludedItems: self.experienceFilter.excludedItems()
    }
});

It works just fine when the two collection items are not parameters and are not passed by the AJAX request. It didn't work when I initially used IEnumerable<string> and changing to List<string> did not work either. Do I need to set a custom route for this to work? Will the interpreter get DateTime but not IEnumerable<T>?

EDIT: Here is the URL being generated with empty collections passed:

(header)/api/ContentApi/GetDashboard?lowerBound=10-12&upperBound=10-23

Here is the URL being generated with some collection items passed:

(header)/api/ContentApi/GetDashboard?lowerBound=10-10&upperBound=10-23&excludedStores%5B%5D=hello&excludedStores%5B%5D=world&excludedExperiences%5B%5D=hello&excludedExperiences%5B%5D=world

I think this is a serialization issue, but I'm not certain.

Source Link
jokul
  • 1.3k
  • 1
  • 16
  • 39

Cannot pass string collection to API controller

I want to pass a collection of strings to an API endpoint:

[HttpGet]
public DashboardSectionViewModel GetDashboard(
    DateTime lowerBound,
    DateTime upperBound,
    [FromUri] List<string> excludedStores = null,
    [FromUri] List<string> excludedItems = null)
{
    //Code
}

Here is where I make the call:

$.ajax({
    url: App.Services.updateUrl + src.updateUrl,
    type: "GET",
    data: {
        lowerBound: self.slideFilter.lowerBoundDisplay(),
        upperBound: self.slideFilter.upperBoundDisplay(),
        excludedStores: self.storeFilter.excludedStores(),
        excludedItems: self.experienceFilter.excludedItems()
    }
});

It works just fine when the two collection items are not parameters and are not passed by the AJAX request. It didn't work when I initially used IEnumerable<string> and changing to List<string> did not work either. Do I need to set a custom route for this to work? Will the interpreter get DateTime but not IEnumerable<T>?