Click here to Skip to main content
14,243,034 members
Rate this:
Please Sign up or sign in to vote.
See more: , +
here is the error that i get

System.InvalidOperationException: Missing parameter: MyParameterName.
   at System.Web.Services.Protocols.ValueCollectionParameterReader.Read(NameValueCollection collection)
   at System.Web.Services.Protocols.UrlParameterReader.Read(HttpRequest request)
   at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters()
   at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

    public class WebService1 : System.Web.Services.WebService
        [System.Web.Script.Services.ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)]

         public List<string> MethodName(string parameterName)
                List<string> result = new List<string>();          

                    using (System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection("connectionstring"))
                        using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("mydbasequery, con))

                            cmd.Parameters.AddWithValue("@xxx", parameterName);

                            System.Data.SqlClient.SqlDataReader dr = cmd.ExecuteReader();
                            while (dr.Read())
                            return result.ToList();
                    return result.ToList();

<pre lang="Javascript">
<pre>  <script type="text/javascript">
      $(document).ready(function () {
      function functionName() {

              source: function (request, response) {
                      async: true,
                      type: "POST",
                      contentType: "application/json; charset=utf-8",
                      data: "{'service_parameter' :'" + $('.classname').val() + "'}",
                      url: 'WebService1.asmx/MethodName',
                      dataType: "json",
                      crossDomain: true,
                      success: function (data) {
                          if (data != null) {                            
                          else {
                      error: function (error) {
              minLength: 10,            

What I have tried:

I tried this code and still getting this error over and over again..
Updated 22-Feb-18 23:46pm
Richard Deeming 9-Feb-18 9:00am
The parameter on your method is called parameterName, but the name you're passing from Javascript is service_parameter.

Is that just an inconsistency introduced when you anonymised your code, or do the names not match in your real code?
Richard Deeming 9-Feb-18 9:02am
Also, you're building the JSON string manually, which won't work if a user enters a single quote in the textbox. You'd do better to use the built-in JSON object:
data: JSON.stringify({ 'parameterName': $('.classname').val() })
JSON.stringify() - JavaScript | MDN[^]
jessrubio 11-Feb-18 22:41pm
thank you for your comment, I try to modify my solution but the error still the same.
ZurdoDev 12-Feb-18 14:15pm
Then you did something wrong. You need to debug it. We can't run it for you. Richard is right, you need to match the parameter name.
jessrubio 12-Feb-18 20:49pm
I already correct the parameterName and service_parameter. they both same as parameterName, I run my code and it runs exactly the way i want it the text is now autocomplete based on my character input but once it inspect it using google chrome Iand on my newtwork tab i've got this error.. "System.InvalidOperationException: Missing parameter: parameterName", is there something with my network. or is it my parameterName?

1 solution

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

Solution 2

Hi,below is the solution :

var serpar_val = $('.classname').val() ;

assign like below:

data: JSON.stringify({ service_parameter: serpar_val }),

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

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