Note that there are some explanatory texts on larger screens.

plurals
  1. PO.autocomplete Issues with ID column
    text
    copied!<p>I want to get something done calling the following action <code>Find</code> in <code>CityController</code>.</p> <p>I can put a break point and see, things look fine data delivered to the client.</p> <ol> <li><p>AutoComplete sort of works when selecting a item; it becomes blank and throws up a weird Javascript exception.</p></li> <li><p>Even though the autocomplete is a part of ui-1.8.9.custom js file, I still need to provide the blow script to it.</p></li> <li><p>When I select a <code>City</code>, I want the <code>CityId</code> to be populated so that I can continue my other search.</p></li> </ol> <pre><code>&lt;link type="text/css" href="/Content/jquery-ui-1.8.9.custom.css" rel="stylesheet" /&gt; &lt;script src="../../Scripts/jquery-1.4.4.min.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="../../Scripts/jquery-ui-1.8.9.custom.min.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="../../Scripts/jquery.autocomplete.js" type="text/javascript"&gt;&lt;/script&gt; &lt;div class="ui-widget" style="float:right"&gt; &lt;label for="city"&gt;City: &lt;/label&gt; &lt;%= Html.TextBox("city") %&gt; &lt;/div&gt; $("input#city").autocomplete('&lt;%= Url.Action("Find", "City") %&gt;', { dataType: 'json', parse: function(data) { alert(data.toString); var rows = new Array(); for(var i=0; i&lt;data.length; i++){ rows[i] = { data:data[i], value:data[i].CityName, result:data[i].CityId }; } return rows; }, formatItem: function(row, i, n) { return row.CityName ; }, width: 300, mustMatch: true, }); public class CityController : Controller { // // GET: /City/ public ActionResult Find(string q) {        var data = from s in DataProvider.CityNames where s.Name.ToLower().StartsWith(q.ToLower()) select new {CityId=s.ID, CityName =s.Name}; var x = data.ToList(); return Json(x,JsonRequestBehavior.AllowGet); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload