MVC Insert text into a label when the button is selected

Asked

Viewed 26 times

1

Prentendo fill a label when I click a button. I created a method, a label and a button. The goal is that when pressing the button, the label is filled with the data I receive.

I have practically everything functional, but when clicking the button ( using the browser I get the results), but they are not inserted in the label, IE, 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);
        }

Knob

<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>

1 answer

2


Instead of using:

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

Use:

$('#email').val(data);
  • Thank you very much, It worked !!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.