https://github.com/PequeCeci/Guava.git first here I leave the project uploaded to github... second here the code
// this is the model that contains both models namespace MyFirstWebsite.Models { public class Model { public List RecipeModel { get; set; } public Slide modelSlide { get; set; }public Modelo(List<Receta> modelo1, Slide modelo2) { modeloReceta = modelo1; modeloSlide = modelo2; } } }
//luego este es mi controller namespace MyFirstWebsite.Controllers { public class HomeController : Controller { private RepositorioRecetas _reposRecetas = null; private Modelo _modelos = null; public List modeloReceta = null; public Slide modeloSlide = null;
public HomeController() { } [HttpPost] public ActionResult Index() { if (ModelState.IsValid) { return RedirectToAction("Index"); } return View(_modelos); } public ActionResult About() { ViewBag.Message = "Your application description page."; return View(); } public ActionResult Contact() { ViewBag.Message = "Your contact page."; return View(); } public ActionResult Recetas(int? id) { if (id == null) { return HttpNotFound(); } var receta = _reposRecetas.GetReceta((int)id); return View(receta); } } }
one of the models has a recipe repository in data, the other model is to make a slider dynamic...
Make your view accept the model type
MyFirstWebsite.Models.Modelo
and change your controller to the following:Or you can also use MVC's ViewBag object:
And you access it from your view like
@ViewBag.Slide
You can find more information about the ViewBag object at http://www.tutorialsteacher.com/mvc/viewbag-in-asp.net-mvc
Greetings.