I am trying to return a list of values to the jquery autocomplete that contains markup. I would think that somewhere I need to be using @Html.raw but can't seem to figure out where to put it. Any suggestions?
Example: Apo A-1 KO - <i>Apoa1<sup>tm1Unc</sup></i>
Here is the razor code:
<b>By Search Term</b><br /> <input type="search" name="searchTerm" style="width:560px" data-jax-autocomplete="@Url.Action("Autocomplete")"/> <input class="submitSearch" type="submit" value="Submit" style="width:100px"/>
Here is the javascript:
$(function () { ///Create Autocomplete var createAutocomplete = function () { var $input = $(this); var options = { source: $input.attr("data-jax-autocomplete"), minLength: 3 }; $input.autocomplete(options); }; $("input[data-jax-autocomplete]").each(createAutocomplete); });
Here is the controller code:
public ActionResult Autocomplete(string term) { // Get the current search results from session SearchResult searchResult = Session["searchResult"] as SearchResult; List<SearchTerm> searchTerms = new List<SearchTerm>(); if (searchResult.DataSheets == null) { // Get the searchTerms from the database searchTerms = searchTermRepository.GetSearchTerms(term); } else { // Get the search terms from searchResult.DataSheets searchTerms = searchTermRepository.GetSearchTerms(term, searchResult.DataSheets); } var projection = from searchTerm in searchTerms select new { label = searchTerm.DisplayName }; return this.Json(projection.ToList(), JsonRequestBehavior.AllowGet); }