Pass data from controller to view using ajax
<p>Hi i select data from database and i want these data pass from my controller to view via ajax but it is not working.</p>

<p>Please can you help me ?</p>

<p>Here is my controller :</p>

<pre><code>[HttpGet]
        public ActionResult Foo(string email_uzivatele)
        {
            var person = AdvertServiceLayer.Instance.SelectByEmail(email_uzivatele);
            return Json(person, JsonRequestBehavior.AllowGet);
        }
</code></pre>

<p>Here i want display email which i select from database:</p>

<pre><code> &lt;input id="email" name="email_uzivatele" type="text" class="form-control input-md"&gt;
</code></pre>

<p>Here is my ajax function:</p>

<pre><code> $(function () {
            function getPerson(email_uzivatele) {
                $.ajax({
                    url: '@Url.Action("Foo", "Home")',
                    type: 'GET',
                    dataType: 'json',

                    cache: false,
                    data: { email_uzivatele: email_uzivatele },
                    success: function (person) {
                        $('#email').val(person.email_uzivatele);
                    }
                });
            }
        });
</code></pre>

<p>Here is function which select email from database:</p>

<pre><code>        public List&lt;Advert&gt; SelectByEmail(string email_uzivatele)
                {



                    string queryString = "SELECT distinct email_uzivatele from 

    Reklama 
    where email_uzivatele like '%" + @email_uzivatele + "%'";
                    // Create the Command and Parameter objects.
                    SqlCommand command = new SqlCommand(queryString, Connection);

                    command.Parameters.AddWithValue("@email_uzivatele", "");

                    // Open the connection in a try/catch block. 
                    // Create and execute the DataReader, writing the result
                    // set to the console window.
                    try
                    {

                        SqlDataReader reader = command.ExecuteReader();
                        List&lt;Advert&gt; advert = new List&lt;Advert&gt;();
                        while (reader.Read())
                        {

                            Advert a = new Advert();
                            a.email_uzivatele = reader[0].ToString();



                            Console.WriteLine("email_uzivatele: " + " " + "
 " + a.email_uzivatele);

                            advert.Add(a);
                        }

                        reader.Close();
                        return advert;
                    }
                    catch (Exception ex)
                    {
                        chyba.zapsat_do_souboru(ex.Message);
                        Console.OpenStandardOutput();
                        Console.WriteLine(ex);
                        //zalogovat chybu
                        return null;
                    }


                }
</code></pre>