public ActionResult SearchAutoComplete(string term)
{
var q =
from x in _movieRepository.All
where x.Title.Contains(term)
select x.Title;
return Json(q.ToArray(), JsonRequestBehavior.AllowGet);
}
public ActionResult SearchAutoComplete(string term)
{
var q =
from x in _movieRepository.All
where x.Title.Contains(term)
select x.Title;
return Json(q.ToArray(), JsonRequestBehavior.AllowGet);
}
Thank you for the immediate reply sir but could you do a webform version of that. Thank you++
Thank you for the immediate reply sir but could you do a webform version of that. Thank you++
Yea, I swore off WebForms years ago, so I suspect you'll get a link or two from others. But in terms of the mechanics, you simply need an endpoint that emits that JSON. To do the JSON you just need to use the JavaScriptSerializer. To design an endpoint,
look into IHttpHandlers in the MSDN docs.
randelramire...
Member
90 Points
81 Posts
How to implement jquery-ui autocomplete with asp.net and json?
Apr 08, 2012 02:25 PM|LINK
I'm studying asp.net and jquery, right now I'm trying to implement a simple autocomplete in PHP I was able to do something like this:
Here's the client code:
<link type="text/css" rel="stylesheet" href="css/jquery-ui-1.8.17.custom.css"/> <script type="text/javascript" src="jquery-1.7.1.js"></script> <script type="text/javascript" src="jquery-ui-1.8.5.custom.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $('.auto').autocomplete( { source: "search.php", focus: function(event, ui) { $(idField).val(ui.item.value); $(this).val(ui.item.label); return false; }, select: function(event, ui) { //$(this).val(ui.item.label); $(this).val(ui.item.label); var a = "#"+$(this).attr('id'); $(a+"hidden").val(ui.item.value); return false; } //minLength: 3 }); }); </script>Here's my code that does the searching:
<?php $host = "localhost"; $user = "root"; $password = ""; $db = "isproj2"; // open connection $connection = mysql_connect($host, $user, $password) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); $text = mysql_real_escape_string($_GET['term']); $query = "Select SupplierName, SupplierID from tbl_supplier where SupplierName LIKE '%$text%'"; $result = mysql_query($query); $data = array(); $first = true; while ($row = mysql_fetch_array($result)) { $data[] = array('label' => $row['SupplierName'], 'value' => $row['SupplierID']); } echo json_encode($data); ?>What I want to happen is do something like this asp.net, In some articles I've read that I need to use a web service.
jquery ui Autocomplete
BrockAllen
All-Star
27534 Points
4907 Posts
MVP
Re: How to implement jquery-ui autocomplete with asp.net and json?
Apr 08, 2012 02:32 PM|LINK
If you're using MVC, then it's this simple:
public ActionResult SearchAutoComplete(string term)
{
var q =
from x in _movieRepository.All
where x.Title.Contains(term)
select x.Title;
return Json(q.ToArray(), JsonRequestBehavior.AllowGet);
}
jquery ui Autocomplete
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
randelramire...
Member
90 Points
81 Posts
Re: How to implement jquery-ui autocomplete with asp.net and json?
Apr 08, 2012 02:41 PM|LINK
Thank you for the immediate reply sir but could you do a webform version of that. Thank you++
jquery ui Autocomplete
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: How to implement jquery-ui autocomplete with asp.net and json?
Apr 08, 2012 02:58 PM|LINK
Refer
http://www.aspsnippets.com/Articles/Using-jQuery-ImageAutoComplete-Plugin-in-ASP.Net.aspx
http://www.aspsnippets.com/Articles/Implement-jQuery-Autocomplete-using-Web-Service-in-ASP.Net.aspx
http://www.aspsnippets.com/Articles/Implement-Key-Value-Pair-with-jQuery-Autocomplete-Plugin-in-ASP.Net.aspx
jquery ui Autocomplete
Contact me
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: How to implement jquery-ui autocomplete with asp.net and json?
Apr 08, 2012 03:03 PM|LINK
Refer
http://www.aspsnippets.com/Articles/Using-jQuery-AutoComplete-Plugin-in-ASP.Net.aspx
http://www.aspsnippets.com/Articles/Implement-jQuery-Autocomplete-using-Web-Service-in-ASP.Net.aspx
http://www.aspsnippets.com/Articles/Implement-Key-Value-Pair-with-jQuery-Autocomplete-Plugin-in-ASP.Net.aspx
Contact me
BrockAllen
All-Star
27534 Points
4907 Posts
MVP
Re: How to implement jquery-ui autocomplete with asp.net and json?
Apr 08, 2012 03:19 PM|LINK
Yea, I swore off WebForms years ago, so I suspect you'll get a link or two from others. But in terms of the mechanics, you simply need an endpoint that emits that JSON. To do the JSON you just need to use the JavaScriptSerializer. To design an endpoint, look into IHttpHandlers in the MSDN docs.
G'dluck :)
jquery ui Autocomplete
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
randelramire...
Member
90 Points
81 Posts
Re: How to implement jquery-ui autocomplete with asp.net and json?
Apr 08, 2012 03:44 PM|LINK
Thank you again sir,yeah I will check that on msdn.com.
asteranup
All-Star
30184 Points
4906 Posts
Re: How to implement jquery-ui autocomplete with asp.net and json?
Apr 09, 2012 05:11 AM|LINK
Hi,
You can check this posts-
http://delicious.com/anupdg/autocomplete+forum
Yo can also check this post-
http://www.burnmind.com/howto/how-to-feed-jquery-uis-autocomplete-with-a-database-generated-dataset
http://www.simonbattersby.com/blog/jquery-ui-autocomplete-with-a-remote-database-and-php/
http://stackoverflow.com/questions/2537721/jquery-ui-autocomplete-with-database
Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog