I have a simple phonebook app that allows the user to search for an employee via a dropdown list of departments or by name via text input. The way I'm handling the search is simply changing the action attribute of the html form with javascript based on whatever they typed or whichever option they selected in the dropdown:
function selectedOption(option) {
var selValue = option.value;
document.getElementById("search-form").action = "/home/index/" + selValue;
}
This works on localhost but when I host it on IIS:
machineName/appName
becomes
machineName/home/index/selValue
cutting off the app name and returning a 404 error
The only way I've been able to get around this is with some hardcoding to check whether "home/index" exists in the path already...
function selectedOption(option) {
var selValue = option.value;
if (window.location.href.includes("home")) {
var searchDest = selValue
} else {
var searchDest = window.location.href + "/home/index/" + selValue
}
document.getElementById("search-form").action = searchDest;
}
This works but it is not very clean or conventional. Is there some way I can have the app name configured in Startup.cs? I saw the same issue in another question here but I'm getting syntax errors when I try to add another MapRoute. This is all that I currently have:
app.UseMvc(routes =>
{
routes.MapRoute("default", "{controller=Home}/{action=Index}/{id?}");
});
Any idea how to get around this?