在同一个页面中添加两个模型实例

时间:2021-07-08 16:49:48

I want to add two instances of my model at the same time, that is the user will enter fill the same form in same page and he will send at the same time the two completed references to the database. Do you have some idea how can I achieve this ?

我想同时添加两个模型实例,即用户将在相同的页面中填写相同的表单,同时他将同时发送两个已完成的数据库引用。你知道我该怎么做吗?

Thank you for your help!

谢谢你的帮助!

2 个解决方案

#1


1  

One thing you could do (and I'm hoping I'm interpreting your question properly) is have a model set up as such:

你可以做的一件事(我希望我能正确地解释你的问题)是建立一个这样的模型:

public class Foo
{
    public int Id { get; set; }
    public string Something { get; set; }
}

public class Bar
{
    public Foo Foo1 { get; set; }
    public Foo Foo2 { get; set; }
}

In your view you would take in a model of Bar (which has contained within it two Foo objects)

在您的视图中,您将采用Bar的模型(其中包含两个Foo对象)

Hopefully this helps, could potentially expand on this if specifics are added to your question.

希望这能对你的问题有所帮助,如果你的问题中有更多的细节的话。

#2


1  

Use View model with two properies of your model:

使用视图模型与您的模型的两个属性:

public class MyViewModel
{
     public Model ModelA { get; set; }
     public Model ModelB { get; set; }
}

#1


1  

One thing you could do (and I'm hoping I'm interpreting your question properly) is have a model set up as such:

你可以做的一件事(我希望我能正确地解释你的问题)是建立一个这样的模型:

public class Foo
{
    public int Id { get; set; }
    public string Something { get; set; }
}

public class Bar
{
    public Foo Foo1 { get; set; }
    public Foo Foo2 { get; set; }
}

In your view you would take in a model of Bar (which has contained within it two Foo objects)

在您的视图中,您将采用Bar的模型(其中包含两个Foo对象)

Hopefully this helps, could potentially expand on this if specifics are added to your question.

希望这能对你的问题有所帮助,如果你的问题中有更多的细节的话。

#2


1  

Use View model with two properies of your model:

使用视图模型与您的模型的两个属性:

public class MyViewModel
{
     public Model ModelA { get; set; }
     public Model ModelB { get; set; }
}