0

I have been trying to implement different examples of jQuery Autocomplete functionality, but none of them work.

The latest one that I have tried implementing is the following example, which seems to be the simplest jQuery Autocomplete functionality example:

Creating Auto Complete From a Hard Coded JavaScript Array http://www.codedigest.com/posts/45/creating-autocomplete-textbox-in-aspnet-mvc

I added the following code in the @section localscripts section of /Shared/BaseTemplates/_Form.cshtml:

Code in @section localScripts section

I then changed '#Country_Name' to '#FullName' and added div id="FullName" on the form that has the field that I want to implement the jQuery Autocomplete functionality on:

Code in form that has the field

I did not include the jquery-3.6.0.js script src in the @section localscripts section of /Shared/BaseTemplates/_Form.cshtml because it is already installed and being referenced else where. Even if I do add it, the jQuery Autocomplete functionality does not work.

This project is written in C# (MVC).

2
  • I was able to make the autocomplete solution work by using <input id="FullName" type="text" class="form-control"/> instead of Html.FormEditorFor. This brings up a new challenge of the value selected via the autocomplete field not saving to the database because it is not linked to a database attribute. I would like to use HtmlFormEditorFor or something else that links to the database attribute to save the autocomplete value.
    – user17824052
    Commented Jan 4, 2022 at 17:22
  • 1
    Please provide enough code so others can better understand or reproduce the problem.
    – Community Bot
    Commented Jan 11, 2022 at 2:26

1 Answer 1

1

The final steps to obtain my solution were:

  1. Remove -> div id="FullName" <- in the Form.cshtml that has the autocomplete field. 2. Change $("#FullName").autocomplete to $("#Street_Street_").autocomplete in the _Form.cshtml that has the @section localscripts section.

*Street is the name of the ViewModel and Street_ is the name of the attribute for the autocomplete field.