ASP.NET MVC通知 - 单击通知时减少总数

时间:2017-10-16 07:06:24

标签: javascript asp.net-mvc notifications

我是MVC的新手。我对通知事情做了些什么。通知部分的设计如下,我在此窗口中列出所有通知:

My Notification Window's Image

我想在此窗口中点击通知时减少上面找到的通知总数。例如:

Example Image

KulNotBildirimPartial.cshtml:

@model List<NoteModel>

<li class="dropdown dropdown-extended dropdown-notification" id="header_notification_bar">
<a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-close-others="true">
    <i class="icon-bell"></i>
    <span class="badge badge-default">@(Model.Where(d=>d.DateSeen==null).Count())</span>
</a>
<ul class="dropdown-menu">
    <li class="external">
        <h3>
            <span class="bold">Notifications</span>
        </h3>
        <a href="@Url.Action("Index", "Note", new { IsUserNotificationList = true })">View All</a>
    </li>
    <li>
        <ul class="dropdown-menu-list scroller" style="height: 250px;" data-handle-color="#637283">
            <li>
                @foreach (var item in Model.ToList())
                {
                    <a href="@Url.Action("Detail", "Note", new { IsUserNotificationList = true, ID = item.NoteID })">
                        <span class="details">
                            You have a note from the user
                            @(item.RelatedUserNameSurname)
                            <br />
                            <br />
                            <span class="label label-sm label-default">@((item.AddDate).ToString("dd.MM.yyyy HH:mm"))</span>
                        </span>
                    </a>
                }
            </li>
        </ul>
    </li>
</ul>

控制器:

[Login]
    public PartialViewResult UserNoteNotificationPartial()
    {
        tbl_User user = Functions.GetUser();
        List<NoteNotificationModel> notenotification = Constants.NoteModel.Where(d => d.RelatedUserID == user.ID && d.NoteID != d.NoteID).ToList();
        var AddNotification = db.tbl_NoteUserRelation.Where(d => d.RelatedUserID == user.ID).ToList();

        if (notenotification.Count > 0)
            AddNotification = AddNotification.Where(d => !notenotification.Any(n => n.NoteID == d.tbl_Note.ID)).ToList();

        List<NoteNotificationModel> All = AddNotification.Select(d => new NoteNotificationModel
        {
            Name = d.tbl_Note.Name,
            Content = d.tbl_Note.Content,
            AddDate = d.tbl_Note.AddDate,
            UserWhoAddetItID = d.tbl_Note.UserWhoAddetItID,
            RelatedUserNameSurname = (d.tbl_Note.tbl_User.Name + " " + d.tbl_Note.tbl_User.Surname),
            RelatedUserID = d.tbl_Note.tbl_User.ID,
            NoteID = d.NoteID,
            DateSeen=d.DateSeen,
        }).ToList();

        foreach (var item in All.ToList())
        {
            notenotification.Add(item);
        }
        Constants.NoteModel = notenotification.ToList();

        return PartialView(notenotification.OrderByDescending(d=>d.AddDate).ToList());
    }

我怎样才能以最简单的方式做到这一点?如果您要插入任何其他代码块,请告诉我。

0 个答案:

没有答案