MVC Insert text into a label when the button is selected

1

I try to fill in a label when I click a button. I created a method, a label, and a button. The purpose is that by pressing the button, the label is populated with the data I receive.

I have almost everything functional, but when I click the button (using the browser I get the results), but they are not inserted in the label, that is, they do not appear as desired.

Method

[HttpPost]
        public JsonResult GetEmails()
        {
            ProjetoEntities entities = new ProjetoEntities();
            var emails = (from Utente in entities.Utente
                          select Utente.Email);
            return Json(emails);
        }

Button

<input type="button" id="btn" value="Select All"/>

Label

<div class="form-group">
  <input class="form-control" type="email" id="email" name="Destinatário" placeholder="Para:">
</div>

Javascript

<script type="text/javascript">

        $(document).on('click', '#btn', function () {

            $.ajax({
                type: 'POST',
                url: '/Email/GetEmails/',
                dataType: 'json',
                success: function (data) {
                    $('#email').html(data);

                    console.log(data);
                }

            });
        });
    </script>
    
asked by anonymous 19.12.2018 / 13:48

1 answer

2

Instead of using:

$('#email').html(data);

Use:

$('#email').val(data);
    
19.12.2018 / 13:55