cant bind my autocomplete search box

2 posts, 0 answers
  1. morteza
    morteza avatar
    18 posts
    Member since:
    Jul 2017

    Posted 05 May 2019 Link to this post

    Hi,

    im using mvc to bind my autocomplete list and use it,to do so,my controller is like:

     public Jsonresult Index()
            {
                //List of parks and turbines while searching

                
                var turbineWindparkList=(from d in DB.Accessinfo
                                         select new OverViewAutoComeplete {

                                             ParkName=d.windpark_name,
                                             TurbineName=d.turbine_name
                                         }).Take(10).ToList();
               
                return Json(turbineWindparkList, JsonRequestBehavior.AllowGet);

               
            }

     

    in my view :

     

    <div><input id="inputAutoComplete" /></div>
     
            
              <script   type="text/javascript">
                     @(Html.Kendo().AutoComplete()
          .Name("inputAutoComplete") //The name of the AutoComplete is mandatory. It specifies the "id" attribute of the widget.
          .DataTextField("ParkName") //Specify which property of the Product to be used by the AutoComplete.
          .DataSource(source =>
           {
              source.Read(read =>
              {
                  read.Action("Index", "Overview"); //Set the Action and Controller names.
              })
              .ServerFiltering(true); //If true, the DataSource will not filter the data on the client.
           })
        )

     

    i dont know whats wrong with my controller which i cant reach to view on page load,and even if i use Actionresult to reach view,i get javascript error on the part razor command

  2. Veselin Tsvetanov
    Admin
    Veselin Tsvetanov avatar
    1190 posts

    Posted 07 May 2019 Link to this post

    Hi Morteza,

    Attached you will find a small MVC sample, which implements an AutoComplete widget initialized with an HTML helper and based on the snippets sent. Here are the most important points on that:

    - HTML helper initialization (@(Html.Kendo().AutoComplete()...) should be outside of the <script> tag;

    - When using HTML helper, you should not place on the page an <input> element with the same ID;

    - I have renamed the endpoint on the server to "Read". An Index action may return a view instead;

    I hope that this helps. If you have any further questions on the Kendo HTML helpers, please do not hesitate to contact us.

    Regards,
    Veselin Tsvetanov
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top