public JsonResult FindByName(string searchText, int maxResults)
{
CustomerFind find = new CustomerFind();
var result = find.FindCustomerByName(searchText, maxResults);
return Json(result, JsonRequestBehavior.AllowGet);
}
Here is my FindCustomerByName:
internal List<Models.Customer> FindCustomerByName(string searchText, int maxResults)
{
List<Models.Customer> result;
using (cummins_sqldb dataContext = new cummins_sqldb())
{
result = (from c in dataContext.Customers
where c.CustomerName.Contains(searchText)
orderby c.CustomerName
select c).Take(maxResults).ToList();
}
return result;
}
The autocomplete is just not functional. I do see values return in JSon though.
ryasn
Member
3 Points
12 Posts
My jQuery autocomplete in a textbox from the database is not working - eyeball my code?
Jun 09, 2012 05:09 PM|LINK
Using MVC3 I have a simple @HTML.Texbox with a class.
Here is my jQuery:
$(document).ready(function () { $("#CustByName").autocomplete( { source: function (request, response) { $.ajax( { url: "/Cases/FindByName", type: "GET", dataType: "json", data: { searchText: request.term, maxResults: 10 }, contentType: "application/json; charset=utf-8", success: function (data) { response($.map(data, function (item) { return { label: item.CustomerName, value: item.CustomerName, id: item.CustomerID } }) ); } }); }, minLength: 3 }); });Here is my controller action:
public JsonResult FindByName(string searchText, int maxResults) { CustomerFind find = new CustomerFind(); var result = find.FindCustomerByName(searchText, maxResults); return Json(result, JsonRequestBehavior.AllowGet); }Here is my FindCustomerByName:
internal List<Models.Customer> FindCustomerByName(string searchText, int maxResults) { List<Models.Customer> result; using (cummins_sqldb dataContext = new cummins_sqldb()) { result = (from c in dataContext.Customers where c.CustomerName.Contains(searchText) orderby c.CustomerName select c).Take(maxResults).ToList(); } return result; }The autocomplete is just not functional. I do see values return in JSon though.
Ryan
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: My jQuery autocomplete in a textbox from the database is not working - eyeball my code?
Jun 10, 2012 10:15 AM|LINK
Refer
http://www.aspsnippets.com/Articles/Implement-jQuery-Autocomplete-using-Web-Service-in-ASP.Net.aspx
Contact me
ryasn
Member
3 Points
12 Posts
Re: My jQuery autocomplete in a textbox from the database is not working - eyeball my code?
Jun 10, 2012 12:37 PM|LINK
Thanks for your assistance. Why would I need a web service? I am using EF and MVC3 Razor. Would this process not work with LINQ?
I am new at MVC so please forgive me.
RameshRajend...
Star
7983 Points
2099 Posts
Re: My jQuery autocomplete in a textbox from the database is not working - eyeball my code?
Jun 10, 2012 12:39 PM|LINK
Hai
Pls look this
http://www.codeproject.com/Questions/184406/Autocomplete-textbox-using-jquery-from-database-in
http://www.aspsnippets.com/Articles/Using-jQuery-AutoComplete-Plugin-in-ASP.Net.aspx
Thank u
asteranup
All-Star
30184 Points
4906 Posts
Re: My jQuery autocomplete in a textbox from the database is not working - eyeball my code?
Jun 11, 2012 03:48 AM|LINK
Hi,
You can check this-
http://delicious.com/anupdg/dropdown+cascading+mvc
Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog
ibrahim.mara...
Member
110 Points
36 Posts
Re: My jQuery autocomplete in a textbox from the database is not working - eyeball my code?
Jun 11, 2012 07:08 AM|LINK
check this
http://www.magic-dev.com/autocomplete-textbox-aspnet-database.htm