So,
I have an application that uses MVC Areas. The route for the controller looks like
[Route("Settings/{something}")]
Then I have an Action
[Route("suggest/{term}")]
public ActionResult Suggest(string something, string term).
I try to call the Suggest action from javascript
var suggestUri = "suggest/";
$searchInput.autocomplete({
source: function (request, response) {
$.ajax({
type: "GET",
url: suggestUri + request.term,
dataType: "json",
success: function (data) {
response(data);
},
error: function (err) {
console.log(err);
}
});
},
minLength: 3
});
From my point of view this ajax call url should be
http://localhost:7311/Settings/firstValue/suggest/term
But the actual result is
http://localhost:7311/Settings/suggest/term
It's missing the {something}
There is for sure something I do wrong, but I have no idea what.
LE: I've done some tests.
If I apply to my controller a different route like
[Route("Settings/{something}/a")]
The result is
http://localhost:7311/Settings/firstValue/suggest/term
When it should be
http://localhost:7311/Settings/firstValue/a/suggest/term
Then i tried to do
[Route("Settings/{something}/a/b")]
The result is
http://localhost:7311/Settings/firstValue/a/suggest/term
When it should be
http://localhost:7311/Settings/firstValue/a/b/suggest/term
It feels like the mvc always leaves out the last parameter from my controller. Any reason?
LE2 :
In Startup.cs the MapRoute looks like this
app.UseMvc(routes =>
{
routes.MapRoute(
name: "somethingBased",
template: "{area:exists}/{somethingBased?}/{controller=Home}/{action=Index}");
routes.MapRoute(
name: "home",
template: "{controller=Home}/{action=Index}/{application?}");
});