1

I want to add an autocomplete (suggestion function) to an editor field in my create menu.

I have this basic razor view @Html.EditorFor(model => model.Title) and I want to add my autocomplete to this.

Previously I have used

<input type="text" name="q"  data-autocomplete="@Url.Action("QuickSearch", "Person")" />
<input  type="submit"  name="submit"  value="Find FullName" />

And I wondered how to implement this.

My Jquery searches for data-autocomplete

$(document).ready(function () {
    $(":input[data-autocomplete]").each(function () {
        $(this).autocomplete({ source: $(this).attr("data-autocomplete") });
   });
})
mcabral
  • 3,524
  • 1
  • 25
  • 42
Stefan Gowlar
  • 35
  • 1
  • 3

1 Answers1

1

You can still do what you previously had

@Html.TextBoxFor(model => model.Title, new { data_autocomplete="/link" })

note that this is TextBoxFor and not EditorFor. Also note the _ in data_autocomplete

I'm not sure about the Url.Action part. You may have to build the url yourself by manually inserting a url rather than use url.action.

Eonasdan
  • 7,563
  • 8
  • 55
  • 82