This question is locked. New answers and comments are not allowed.
Hello,
I'm trying to use the AutoComplete control. For databinding I'm using Ajax:
@(Html.Telerik().AutoComplete()
.Name("searchCollaborators")
.DataBinding(binding => binding.Ajax().Select("SearchByName", "id"))
.HighlightFirstMatch(true)
.AutoFill(true)
)
In my controller I've set the following action:
public ActionResult SearchByName(string text) {
List<Employee> employees = Facade.Employee.GetEmployeeByName(text);
List<EmployeeDescription> result = new List<EmployeeDescription>();
foreach (Employee employee in employees) {
result.Add(new EmployeeDescription() { Id = employee.Id, Name = employee.Name });
}
return new JsonResult { Data = result };
}
the class EmployeeDescription is just a dummy DTO that contains the Name and Id properties):
public class EmployeeDescription {
public string Name { get; set; }
public int Id { get; set; }
}
I've also set the following rule in the Global.asax.cs:
routes.MapRoute(
"SearchEmployeesByName", // Route name
"id/SearchByName/{nameFilter}", // URL with parameters
new { controller = "Identity", action = "SearchByName", nameFilter = UrlParameter.Optional } // Parameter defaults
);
When I try to use the autocomplete by entering some text, the ajax call is ok. The breakpoint enters my action, filters the data and sends back a valid JsonResult.
The returned type is application/json, POST is 200, so I guess everything is ok. However, the autocomplete is not shown, and the following errror occurs in the jquery source code:
Uncaught TypeError: Object #<Object> has no method 'replace'
I've created my project using the Telerik template, and I'm only using the jquery from the telerik asset.axd handler.
The scriptregistrar is also in place (was added by the Telerik Visual Studio 2010 template when I created the project), everything seems to be on place and I can't figure out what is wrong.
[UPDATE]: I'm using Telerik.Web.Mvc.dll, version 2011.1.315.340
Any ideas?
Thanks.
Lucian
I'm trying to use the AutoComplete control. For databinding I'm using Ajax:
@(Html.Telerik().AutoComplete()
.Name("searchCollaborators")
.DataBinding(binding => binding.Ajax().Select("SearchByName", "id"))
.HighlightFirstMatch(true)
.AutoFill(true)
)
In my controller I've set the following action:
public ActionResult SearchByName(string text) {
List<Employee> employees = Facade.Employee.GetEmployeeByName(text);
List<EmployeeDescription> result = new List<EmployeeDescription>();
foreach (Employee employee in employees) {
result.Add(new EmployeeDescription() { Id = employee.Id, Name = employee.Name });
}
return new JsonResult { Data = result };
}
the class EmployeeDescription is just a dummy DTO that contains the Name and Id properties):
public class EmployeeDescription {
public string Name { get; set; }
public int Id { get; set; }
}
I've also set the following rule in the Global.asax.cs:
routes.MapRoute(
"SearchEmployeesByName", // Route name
"id/SearchByName/{nameFilter}", // URL with parameters
new { controller = "Identity", action = "SearchByName", nameFilter = UrlParameter.Optional } // Parameter defaults
);
When I try to use the autocomplete by entering some text, the ajax call is ok. The breakpoint enters my action, filters the data and sends back a valid JsonResult.
The returned type is application/json, POST is 200, so I guess everything is ok. However, the autocomplete is not shown, and the following errror occurs in the jquery source code:
Uncaught TypeError: Object #<Object> has no method 'replace'
I've created my project using the Telerik template, and I'm only using the jquery from the telerik asset.axd handler.
The scriptregistrar is also in place (was added by the Telerik Visual Studio 2010 template when I created the project), everything seems to be on place and I can't figure out what is wrong.
[UPDATE]: I'm using Telerik.Web.Mvc.dll, version 2011.1.315.340
Any ideas?
Thanks.
Lucian