Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I modified my code like below, it works perfect! Thanks "jk." !!!</p> <p>The view code is like below:</p> <pre><code>&lt;head runat="server"&gt; &lt;link href="../../Content/jquery-ui-1.8.14.custom.css" rel="stylesheet" type="text/css" /&gt; &lt;script src="../../Scripts/jquery-1.6.2.min.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="../../Scripts/jquery-ui-1.8.14.custom.min.js" type="text/javascript"&gt;&lt;/script&gt; &lt;/head&gt; &lt;script type="text/ecmascript"&gt; $(document).ready(function () { $.ajax({ type: "GET", url: "/Product/GetProductName/", dataType: "json", contentType: "application/json; charset=utf-8", data: { categoryID: &lt;%: Model.Select(o =&gt; o.Category.CategoryName).Distinct().Count() &gt; 1 ? 0 : Model.FirstOrDefault().CategoryID %&gt; }, success: function(data) { if (data.length &gt; 0) { var dataFromServer = []; for (i = 0 ; i &lt; data.length; i++) { dataFromServer[i] = data[i].ProductName; } }; $('#productNameSearch').autocomplete({ source: dataFromServer }); }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert(textStatus); } }); }); &lt;/script&gt; &lt;% using (Html.BeginForm("ProductNameSearch", "Product", FormMethod.Post)) {%&gt; &lt;input type="text" id="productNameSearch" name="productNameSearch" style="width:300px" /&gt;&amp;nbsp; &lt;input type="submit" value="Go!" /&gt; &lt;%}%&gt; </code></pre> <p>The controller code is like below:</p> <pre><code>[HttpGet] public ActionResult GetProductName(int? categoryID) { Product product = new Product { CategoryID = categoryID }; return Json(from p in pr.SearchProductList(product) select new { ProductName = p.ProductName }, JsonRequestBehavior.AllowGet); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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