Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MVC jQuery
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 7-Feb-13 17:48pm
Hesha764
Edited 7-Feb-13 17:50pm
v3
Comments
Hesha at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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:
source: function( request, response ) {
 
          $.getJSON( "/Home/AutocompleteSuggestions", {
 
            ss: request.term
 
          }, response );
 
        },
 
You can find more info on JQuery documentation about autocomplete and getJSON.
  Permalink  
Comments
Hesha at 11-Feb-13 1:39am
   
Thanks dude. but it also passing a Null value to controller. can you bit explain the jquery? Thanks
Hesha at 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 at 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 at 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)

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 Sergey Alexandrovich Kryukov 130
4 DamithSL 95
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 9 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100