My API code
[HttpGet("/GetBusinessDaysWithPublicHolidayDates/")]
public int GetBusinessDays(DateTime startDate, DateTime endDate,[FromQuery] IList<DateTime> publicHolidays)
{
var noOfDays = _dayCalculatorService.BusinessDaysBetweenTwoDates(startDate, endDate, publicHolidays);
return noOfDays;
}
My API call from Vue js code:
var arr = JSON.stringify(this.publicHolidays);
axios.get('https://localhost:7054/GetBusinessDaysWithPublicHolidayDates', {
params: {
startDate: this.startdate,
endDate:this.enddate,
publicHolidays:JSON.parse(arr)
URL is created in this format:
https://localhost:7054/GetBusinessDaysWithPublicHolidayDates?publicHolidays[]=2022-06-16T14:39:00.000Z&publicHolidays[]=2022-06-20T14:39:00.000Z
But API is working with this URL:
https://localhost:7054/GetBusinessDaysWithPublicHolidayDates?publicHolidays=2022-06-16T14:39:00.000Z&publicHolidays=2022-06-20T14:39:00.000Z
How to achieve this?
CodePudding user response:
You can pass the date and time as an array using JSON.stringify.
this.$axios.get('/GetBusinessDaysWithPublicHolidayDates/', {
params: {
q: JSON.stringify(result)
}
})
And URL for the API call will get created as
http://localhost:7054/cidade/?q=[value1,value2]