sajiii
sajiii

Reputation: 172

Fill dropdown with jquery ajax ASP.NET MVC

i want to get all notifications with signal R and i want to fill drop-down list with all notifications coming from database...i received all notifications but when i display on drop-down...all are not in proper format ..these all are just like a single notification...enter image description here

controller===>>>

 public ActionResult GetMessages()
        {
           MessagesRepository _messageRepository = new MessagesRepository();
            return PartialView("_MessagesList", _messageRepository.GetAllMessages());
        } 

View==>>>

 function getAllMessages()
               {
                   var tbl = $('#messagesTable');
                   $.ajax({
                       url: '/Home/GetMessages',
                       contentType: 'application/html ; charset:utf-8',
                       type: 'GET',
                       cache:'false',
                       dataType: 'html'
                   }).success(function (result) {

                       $.notiny({
                           text: 'New Notification Available You May Check',
                           animation_hide: 'custom-hide-animation 0.5s forwards'
                       });

                       tbl.empty().append(result);


                   }).error(function () {

                   });


               }

Upvotes: 2

Views: 300

Answers (1)

Sajid Ishaq
Sajid Ishaq

Reputation: 123

In your _Message view you should write your code in <table> tag... like this

_message==>>

<table>
    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Message)

                @Html.DisplayFor(modelItem => item.EmptyMessage)

            </td>
        </tr>


    }

</table>

Upvotes: 1

Related Questions