There is a need to get some data for an autocomplete ajax request. I reviewed a bunch of examples in the internet and in each of them there is something like this:
data-autocomplete-source='@Url.Action("MyAction", "MyController")' However, this does not work. Perhaps you need to make the correct routing, but it does not work for me. If you write a direct link instead of target.attr("data-autocomplete-source") , as shown in the code, then everything works.
$(document).ready(function () { $(".searchField").each(function () { var target = $(this); target.autocomplete({ source: function (request, response) { $.post("/MyController/MyAction/", request, response); }, minLength: 1 }); }); }); Routing:
routes.MapRoute ( "AutocompleteSearch", // Route name "{controller}/{action}", // URL with parameters new { controller = "MyController", action = "MyAction" }