sajiii sajiii - 5 months ago 37
jQuery Question

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 () {

});


}

Answer

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>