locked
paging in viewmodel in net core 2.2 RRS feed

  • Question

  • User1051638994 posted

    Hello I have a viewmodel 

      public class VMTicketReply
        {
            public PaginatedList<Ticket> Tickets { get; set; }
    
            public IEnumerable<Replies> Replies { get; set; }
        }

    I have read this tutorial but is for single model

    Now in my view I show my tickets with corresponding replies

    return View(model)



    I try to return my viewmodel to pagelist but without success

    My controller gets data from viewmodel

     VMTicketReply model = new VMTicketReply();
    
                model.Tickets = (from t in _context.Tickets.Include(t => t.Categories).Include(t => t.InterestedCategories).Include(t => t.Priorities).Include(t => t.Tmimata).Include(t => t.Conditions).Include(t => t.TicketKind).Include(t => t.ContactKind)
    
                                 select t);
    
                model.Replies = (from r in _context.Replies
    
                                 select r);
    

    How can I achive that? Is that possible?

    thank you

    Saturday, November 14, 2020 9:59 AM

All replies

  • User475983607 posted

    The ViewModel design does not support this requirement.  The model must represent a one-to-many relationship.

    public class VMTicketReply
    {
        public int TicketId { get; set; }
        public string TicketText {get; set;}
    
        public List<Replies> Replies { get; set; }
    }

    I strongly recommend that you go through a few beginning level MVC and Entity Framework tutorials to learn the basics.  

    Saturday, November 14, 2020 12:10 PM