This is a migrated thread and some comments may be shown as answers.

cant bind my autocomplete search box

1 Answer 79 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
morteza
Top achievements
Rank 1
morteza asked on 05 May 2019, 10:09 PM

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

1 Answer, 1 is accepted

Sort by
0
Veselin Tsvetanov
Telerik team
answered on 07 May 2019, 02:00 PM
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.
Tags
General Discussions
Asked by
morteza
Top achievements
Rank 1
Answers by
Veselin Tsvetanov
Telerik team
Share this question
or