0

I've created Entire my project with Model from ORACLE and Then Controller with Type "MVC5 Controller with View using Entity Framework".

Now the requirement is to consolidate new model in my existing View, How do i don that ? I need to know how to add multiple Model in Single Controller/View.

Steps/Screen Shots would be appreciated.

2 Answers2

0

Here are some useful examples and along the lines of what I was going to suggest:

https://www.c-sharpcorner.com/UploadFile/ff2f08/multiple-models-in-single-view-in-mvc/

MVC 5 Multiple Models in a Single View

In short, use a ViewModel class to bundle multiple model classes to send to the view.

A snippet from the accepted answer of the referenced stackoverflow Link:

public class ToPage
{
    public WebsiteTheme WebsiteTheme{ get; set; }
    public User User { get; set; }

    public ToPage() {
         websiteTheme = new WebsiteTheme();
         user = new User();
    }
}
eaglei22
  • 2,589
  • 1
  • 38
  • 53
  • This is not much useful, I suspect to create new .cs file which can encompass the both table property, How ? Once new .CS file created how i can map that to the Controller type"MVC5 Controllor with View using Entity Framework" ? This is kind of nearly matching post, However i'm looking for 2 View in a Model this is only for Single Model. https://www.c-sharpcorner.com/UploadFile/219d4d/working-with-multiple-tables-in-mvc-using-entity-framework/ – user12730247 Feb 06 '20 at 10:27
  • I am a bit confused as I haven't used EF in the way you're describing. You wrap your two child view models into your main wrapper (that will be passed to the view) then you can access each view model using dot operator. So, @Html.TextBoxFor(m => m.ClassB.PartNumber) Each child viewModel will maintain its own access to the dbContext of EF to CRUD. – eaglei22 Feb 06 '20 at 14:57
  • Yes , That is what my intention is , Is that possible any ways ? – user12730247 Feb 07 '20 at 08:52
-1

Just use this template to get started. https://youtu.be/912q3TEF25U