简体   繁体   English

想要将多个模型传递给视图ASP .NET MVC4

[英]Want to pass multiple models to a view ASP .NET MVC4

I am using ASP .NET MVC4 structure. 我正在使用ASP .NET MVC4结构。 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. 首先,我开始将Messages重命名为Message因为它在概念上代表一条消息,而不是集合。

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. 取而代之的是,我将使用一个jQuery标签(或类似标签),该标签将在页面的基础上向Json MVC操作查询查询消息。

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. 无法给出具体的示例,因为有很多方法可以实现此目的,但是基本原理是在需要时使用ajax查询必要的数据,并将其限制为具有MVC(或WebAPI)操作的页面。

But if you don't care about performance, and its something quick you want I would do as Matt Bodily suggested. 但是,如果您不关心性能,而又想快速了解性能,我会按照Matt Bodily的建议做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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