Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi every one
i get a jquery for the Auto completion textbox and following query only pass null values to the controller .if you could assist me on this matter that would be a great help!!!

input id="searchTerm" name="searchTerm1" type="text" /> 

     <script type="text/javascript">
         $(function () {
             $("#searchTerm").autocomplete({   
                 source: "/Home/AutocompleteSuggestions",
                 minLength: 1,
                 select: function (event, ol) {
                     if (ol.item) {
                         $("#searchTerm").val(ol.item.value);
                         $("form1").submit();
                     }
                 }
             });
         });
    </script>


//in controller class

 public JsonResult AutocompleteSuggestions(string ss)
        {
            var suggestions = selectEmployees.getEmployeeSuggestedNames(ss);
            return Json(suggestions, JsonRequestBehavior.AllowGet);
        }
Posted
Updated 7-Feb-13 16:50pm
v3
Comments
Hesha 8-Feb-13 3:02am    
i just notice that the valueget from the textbox is always null.i dntknow why this is happening? controller signature is working fine.

1 solution

This happen because in your script you provide only the url of the action but don't provide any value for [ss].
You must use another syntax that allow providing [ss] value in remote call, for example using a function as source for autocomplete and an explicit JSON call to remote server:
JavaScript
source: function( request, response ) {

          $.getJSON( "/Home/AutocompleteSuggestions", {

            ss: request.term

          }, response );

        },


You can find more info on JQuery documentation about autocomplete and getJSON.
 
Share this answer
 
Comments
Hesha 11-Feb-13 1:39am    
Thanks dude. but it also passing a Null value to controller. can you bit explain the jquery? Thanks
Hesha 11-Feb-13 1:57am    
This is the suggested function i used : but still it returning Null vale :)
<pre>


<script type="text/javascript">

source:(function (request, response ) {

$.getJSON( "/Home/AutocompleteSuggestions",{
ss: request.new1
},response);
minLength: 1,
select: function (event, ol) {
if (ol.item) {
$("#new1").val(ol.item.value);
$("form").submit();
}
}
});
});
</pre>
Roberto Ferraris 11-Feb-13 4:31am    
Hi, I've provided only the source: part of javascritp. It is intended to replace
source: "/Home/AutocompleteSuggestions",
not all the settings, minLength and select must remain outside of source: part.
Hesha 11-Feb-13 5:05am    
Now its ok dude. i changed controller signature para as (String "term")then its getting the j query values from the view. i dnt know how this is happening but if i change that to any other name for para it will not be working :)
Thanks a Lot dude!!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900