0

I've just downloaded and installed

  • typeahead.bundle.min.js
  • typeahead.mvc.model.js
  • typeahead.css

I've followed the example given and I have a helper in my view

@Html.AutocompleteFor(model => model.NewUser.User_Org, model => model.NewUser.User_Org,"GetOrganisations", "User", false, new { htmlAttributes = new { @class = "form-control" } })

and this action method on my controller

[ActionName("GetOrganisations")]
    [ValidateAntiForgeryToken]
    public ActionResult GetComboData(string search)
    {
        JsonResult result = new JsonResult();
        if (!string.IsNullOrEmpty(search))
        {
            GetOrganisationRequestNonPrimary request = new GetOrganisationRequestNonPrimary(search);
            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            var organisations = this._organisationService.OrganisationAutoComplete(request);
            result.Data = organisations.Organisations.AsQueryable();
            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
        }

        return result;
    }

The input box is rendered but when I start typing, nothing happens, I would expect my action method to be hit on the controller, but it isn't. I've got all the prerequisites for typeahead and the mvc helper, yet it just wont work. Is there something I'm missing?

Mark Schultheiss
  • 32,614
  • 12
  • 69
  • 100
  • Can you possibly show the rendered output of the helper? Does that contain the JavaScript to initialize the plugin? – Mark Schultheiss Apr 07 '17 at 13:38
  • Why the duplicate line `result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;`? Not your issue I think but just curious. – Mark Schultheiss Apr 07 '17 at 13:53
  • the problem seemed to be related to the antiforgerytoken. Its included in the form but not pased to the controller action so i commented it out and the controller code is now being hit and its returning some data. The problem now is its not being displayed, the drop down appears and its empty, but I still ant explain the antiforgerytoken problem – user2347338 Apr 07 '17 at 15:36
  • duplicate JsonRequestBehaviour was just an error, removing it made no difference – user2347338 Apr 07 '17 at 15:37
  • this is whats rendered, the only javascript are the libraries typeahead.bundle.min and typeahead.mvc.model – user2347338 Apr 07 '17 at 15:42
  • – user2347338 Apr 07 '17 at 15:44
  • sorry, the markup was over 1000 characters too long so ive had to truncate it, hopefully this will be of some help – user2347338 Apr 07 '17 at 15:44
  • Put that in the question and format it for visibility. Include any script it has included/generates as well. – Mark Schultheiss Apr 07 '17 at 19:08
  • Look here for clues on the token issue, I wondered about that but did not dig into the JS code. http://stackoverflow.com/questions/2906754/how-can-i-supply-an-antiforgerytoken-when-posting-json-data-using-ajax – Mark Schultheiss Apr 07 '17 at 19:23

0 Answers0