Skip to content

My Typeahead remote is not showing results #261

@TariqueIqbal

Description

@TariqueIqbal

Hi there,
My typeahead remote not showing results. Can any one help?

  1. Here is my Json:
    {"serials":[{"value":"CXJZ5M1"},{"value":"CXJZ5M2"},{"value":"CXJZ5M3"},{"value":"CXJZ5M4"},{"value":"CXJZ5M5"},{"value":"CXJZ5M6"},{"value":"CXJZ5M7"},{"value":"CXJZ5M8"},{"value":"CXJZ5M9"},{"value":"CXJZ510"}]}

  2. My script in the View:

var states1 = new Bloodhound({
    datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
    queryTokenizer: Bloodhound.tokenizers.whitespace,
    remote: {
      url: "/Distribution/SearchAssetSerialsofAssetJson?id=1008", 
      wildcard: '%QUERY'
    }
});
$('#the-basics .typeahead').typeahead(null,
{
  name: 'serials',
  display: 'value',
  source: states1
});
  1. Here is my Controller-Action:
    ```
    public JsonResult SearchAssetSerialsofAssetJson(int id)
    {
    if (id <= 0) { return Json(new { label = "Invalid Asset" }); }

         Configuration conf = _context.Configuration.FirstOrDefault();
         if (conf == null)
         {
             return Json(new { label = "Configuration not found." });
         }
    
         if (conf.InventorySystemType == (int)InvetorySystemTypeEnum.LIFO)
         {
             var serials = (from s in _context.StoreAssetSerial
                            join st in _context.Store on s.StoreId equals st.Id
                            join a in _context.Assets on st.AssetId equals a.Id
                            where s.AssetStatusId == (int)AssetStatusEnum.InStore && st.AssetId == id //&& s.SerialNo.Contains(txtSerial)
                            orderby s.LabeNo descending
                            select new
                            {
                                value = s.SerialNo
                            }).Take(10);
    
             return Json(new { serials });
         }
         else
         {
             var serials = (from s in _context.StoreAssetSerial
                            join st in _context.Store on s.StoreId equals st.Id
                            join a in _context.Assets on st.AssetId equals a.Id
                            where s.AssetStatusId == (int)AssetStatusEnum.InStore && st.AssetId == id //&& s.SerialNo.Contains(txtSerial)
                            orderby s.LabeNo ascending
                            select new
                            {
                                value = s.SerialNo
                            }).Take(10);
    
             return Json(new { serials });
         }
     }
    
**Another thing:** How can I pass parameter in the remote: url: (say like, url: `"/Distribution/SearchAssetSerialsofAssetJson?id=" + $(#txtAssetId).text()`)

Thanks in Advance
Tarique Iqbal

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions