I have two jQuery autocomplete textboxes on a mvc web page. One that returns a list of questions and another that returns a list of tags.
The questions textbox works perfectly but the tags text box only sends a null string to its controller.
The jQuery javascript is an exact match apart from the Url.Action, the non working one is displayed below:
<script type="text/javascript">
$(document).ready(function() {
$('#searchTag').autocomplete('<%= Url.Action("AutoComplete", "Tags") %>', {
dataType: 'json',
parse: function(data) {
var rows = new Array();
for (var i = 0; i < data.length; i++) {
rows[i] = { data: data[i], value: data[i].Name, result: data[i].Name };
}
return rows;
},
formatItem: function(row) {
return row.Name;
},
delay: 40,
autofill: true,
selectFirst: false,
highlight: false,
multiple: true,
multipleSeparator: ";"
});
});
</script>
The Tags Controller is called and returns the Json data correctly as I have hard coded a 'b' string parameter to the LookUpTag method to make sure, but the string t parameter for AutoComplete is always null.
public ActionResult AutoComplete(string t)
{
IQueryable<Tag> searchResults = tagRepository.LookUpTag("b");
var data = (from searchResult in searchResults
select new { Id = searchResult.ID, Name = searchResult.Name }).ToList();
return Json(data);
}
Is there any logical reason for this?