I have an HomeController and in Index action i want work with multiple objects, for example i’ll show News, Pictures, Portfolio in HomePage. So how can i pass multiple Objects to View.
public ActionResult Index()
{
var news = newsRepository.GetAll();
return View(news);
}
Above, i can pass only News object to view. But as you know in HomePage of a website there will be more than only one object.
On the view when i only work with News, i can pass “IEnumerable” from a controller. But to declare more than one object in the view, what should i do? Sorry i’m a beginner in MVC3. In WebForms it was easy with user controls or .NET controls but in MVC it looks complicated.
Thanks
What I do to solve this is use a view model with properties that contain the objects you want to pass in to the view.
I create a ViewModel folder for these classes.
In your controller.