简体   繁体   中英

Want to pass multiple models to a view ASP .NET MVC4

I am using ASP .NET MVC4 structure. I want show messages list with different category like inbox, outbox and trash etc. message on my view. How can I pass multiple modal data to a single view that will show data with respective category. For example I want to show trash message inbox messages and sent messages in view then how can I pass all data with respective category to the view.

Here I have messages class that i want to use to pass data to view.

public class Messages
{
    public int message_Id { get; set; }
    public string message_subject { get; set; }
    public string message_description { get; set; }
    public System.DateTime message_date { get; set; }
    public int sender { get; set; }
    public int project_id { get; set; }
    public string message_size { get; set; }
    public string file_id { get; set; }
    public int reciever { get; set; }
    public int star { get; set; }
    public int read { get; set; }
    public string sender_name { get; set; }
    public string reciever_name { get; set; }
    public string type { get; set; }
    public int isActive { get; set; }
}

Please if there any mistake to explain my problem please edit it. I have not good command in English. Thanks

create a view model

public class ViewModel{
    public List<Messages> Inbox { get; set; }
    public...
}

First, I would start my renaming Messages to Message as it conceptually represents one message, not a collection.

Second, creating one single view for the whole thing may not be wise because it would imply to me that you are going to go to your data store and query all these messages at the same time.

Instead I would with a jQuery tab (or something similar) that would go and query an Json MVC action query for messages, on a paged basis.

Can't give a concrete example because there are so many ways to implement this, but the basics are to query for the necessary data upon when needed with ajax, limiting it to a page with an MVC (or WebAPI) action.

But if you don't care about performance, and its something quick you want I would do as Matt Bodily suggested.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM