I am trying to get two query string parameters from JavaScript to the controller. Here is the code:
JavaScript
var startDate = "",
enddate = "";
var startDate = $.datepicker.formatDate(dateFormat, $("#startDate").datepicker('getDate'));
var enddate = $.datepicker.formatDate(dateFormat, $("#endDate").datepicker('getDate'));
if (startDate != "" || enddate != "") {
window.location = `${window.location.href}/Index?startDate=${startDate}&endDate=${enddate}`;
}
C#
public IActionResult Index([FromQuery(Name = "startDate")] string startDate = "", [FromQuery(Name = "endDate")] string endDate = "")
{
}
The controller gets called, and the first parameter is fin but the second parameter gets a messed up version of the URL. Here is a picture. I am having a hard time figuring out what I am doing wrong.
JavaScript Values
C# values


startDateandendDatein javascript? Also, why are you declaring the variables twice in JS? Also, using just[FromQuery]should be enoughwindow.location.hrefin the JavaScript?