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" /> 
 
<pre>
 &lt;script type=&quot;text/javascript&quot;&gt;
     $(function () {
         $(&quot;#searchTerm&quot;).autocomplete({   
             source: &quot;/Home/AutocompleteSuggestions&quot;,
             minLength: 1,
             select: function (event, ol) {
                 if (ol.item) {
                     $(&quot;#searchTerm&quot;).val(ol.item.value);
                     $(&quot;form1&quot;).submit();
                 }
             }
         });
     });
&lt;/script&gt;

//in controller class

public JsonResult AutocompleteSuggestions(string ss)
{
var suggestions = selectEmployees.getEmployeeSuggestedNames(ss);
return Json(suggestions, JsonRequestBehavior.AllowGet);
}

Posted 7-Feb-13 17:48pm
Hesha769
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 ) {
 
<pre>
      $.getJSON( &quot;/Home/AutocompleteSuggestions&quot;, {
 
        ss: request.term
 
      }, response );
 
    },</pre>

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 455
1 Sergey Alexandrovich Kryukov 445
2 Maciej Los 290
3 ProgramFOX 275
4 CHill60 225
0 OriginalGriff 550
1 Sergey Alexandrovich Kryukov 470
2 Maciej Los 310
3 ProgramFOX 275
4 Peter Leow 250


Advertise | Privacy | Mobile
Web04 | 2.8.150331.1 | Last Updated 9 Feb 2013
Copyright © CodeProject, 1999-2015
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