Click here to Skip to main content
15,900,254 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
the function

public ActionResult Recherche(string countryCode2)
       {
           string CS = "data source=.; database = DB; integrated security = SSPI";
           SqlConnection con = new SqlConnection(CS);
           SqlCommand cmd  = new SqlCommand("SELECT * FROM EMP WHERE SUBSTRING(Nom_commun, 1, 5) = @countryCode2  ORDER BY Nom_commun ASC", con);
           con.Open();
           SqlDataReader reader = cmd.ExecuteReader();


           List<Models.EMP > result = new List<Models.EMP >();
           while (reader.Read())
           {
               Models.EMP item = new Models.EMP ()
               {
                   Id = (int)reader["Id"],
                   Numero= reader["Numero"].ToString(),
                   Nom = reader["Nom"].ToString(),
                   Diametre= reader["Diametre"].ToString(),
                   Consigne= reader["Consigne"].ToString()
               };
               result.Add(item);
               con.Close();
           }
           return View(result);

       }



code javascript


<script src="~/Scripts/jquery-3.3.1.js"></script>
<script>
           $('#Lsite').change(function () {
                var selectedCountry = $("#Lsite").val();
                 if (selectedCountry != null && selectedCountry != '') {
                    $.getJSON('@Url.Action("Recherche")', { countryCode2: selectedCountry }, function (result) {
                        if (result != null && !jQuery.isEmptyObject(result))
                        {

                                 var result = {};
                                 table.find('tr').each(function (commdnp3form) {
                                     var $result = $(this).find('td'),
                                         Numero = $result.eq(1).text(),
                                         Nom = $result.eq(2).text();
                                         Consigne= $result.eq(3).text();

                              });
                        }

                    });
                 }

            });
</script>


What I have tried:

<pre>
I have to display the data after the choice coming from the combobox.



the code must apply a function which has for parametre the choice of combobox
Posted
Updated 21-Nov-19 22:18pm
Comments
F-ES Sitecore 22-Nov-19 5:07am    
Just google how to use jQuery ajax and MVC for code examples, there are too many things wrong with this code to bother fixing it up.
Member 14663996 22-Nov-19 10:51am    
thank you

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