I have two ASP NET sites. They has different logic and pages, getting/writing data from different databases. I want to create a Master layout (with header, menu footer ect) and join this sites like they are looks like one single site. So the question is is it possible? Thanks.
Asked
Active
Viewed 36 times
1 Answers
0
You want to achieve something like displaying different models in one view? If yes, then you can use ViewModels
. Create viewModel
class and in here include what models do you want to display.
public class ViewModel
{
public Book Book { get; set; }
public IEnumerable<Book> Books { get; set; }
public Genre Genre { get; set; }
public IEnumerable<Genre> Genres { get; set; }
//and so on...
}
Then in your action method you need to create new viewModel and pass it to the return view.
var viewModel = new ViewModel
{
Books= db.Books.ToList(),
Genres = db.Genres.ToList()
//you can also of course specify here a Book or Genre
};
return View(viewModel);
In your view/or layout specify the model what you are using.
@model YourProjectName.ViewModels.ViewModel
And now you have access to all properties what you have specified in viewModel
class.
More about View Models: