下划线无法从api“''未定义的数据中读取数据

时间:2016-12-21 13:24:41

标签: javascript c# asp.net-mvc api underscore.js

我正在尝试从API中读取一些数据并且不断获取:

  

未定义错误.Uncaught TypeError:无法读取未定义的属性“DateTime”。

这似乎是指行:

<script type="text/x-template" id="notifications-template">
    <ul>
        <%
        _.each(notifications, function(notification){
        if(notification.type==1){%>
        <li> has canceld the bla  <%= notification.lecturegig.DateTime %></li>
       <% }
        })
        %>
    </ul>
        </script>

<script>
    $(document).ready(function() {
        $.getJSON("/api/notifications",
            function(notifications) {
                $(".js-Notifications-count")
                    .text(notifications.length)
                    .removeClass("hide")
                    .addClass("animated bounceInDown");
                $(".notifications").popover({
                    html: true,
                    title: "Notifications",
                    content: function () {
                        var compiled = _.template($("#notifications-template").html());
                       return  compiled({ notifications:notifications });
                        return html;
                    },
                    placement: "bottom"
                });
            });
    });
</script>

对我看起来(我最好的猜测)db表名是问题所在。 在我的调试模式中,我可以看到我有数据&amp; (popover正在通知1个数据项)。

 public IEnumerable<NotificationDto> GetNewNotifications()
    {
        var useId = User.Identity.GetUserId();

        var notification = _context.UserNotifications
            .Where(un => un.UserId == useId && !un.IsRead)
            .Select(un => un.Notification)
            .Include(n => n.LectureGig.Artist)
            .ToList();}

我的api

 public class Notification
{
    public int Id { get; private set; }
   //Property
    [Required]
    public LectureGig LectureGig { get; private set; }

    protected Notification()
    {

    }

    private Notification(NotificationType type, LectureGig lecturegig)
    {
        if (lecturegig == null)
            throw new ArgumentNullException("lecturegig");

        Type = type;
        LectureGig = lecturegig;

        if (Datetime.HasValue)
        {
            Datetime = DateTime.Now;
        }
    }
    public static Notification GigCanceld(LectureGig lecturegig)
    {
        return new Notification(NotificationType.LectureGigCanceled, lecturegig);
    }

&安培;班级

Access-Control-Expose-Headers: Authorization, Permissions

0 个答案:

没有答案