I have a Partial View that goes like this:
@model IEnumerable<NutricionApp.Models.Ingrediente>
<table>
<tr>
<th>
NombreIngrediente
</th>
<th>
CantidadPorPorcion
</th>
<th>
UnidadPorPorcion
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.NombreIngrediente)
</td>
<td>
@Html.DisplayFor(modelItem => item.CantidadPorPorcion)
</td>
<td>
@Html.DisplayFor(modelItem => item.UnidadPorPorcion)
</td>
</tr>
}
</table>
I want to render said partial view in this View, that is strongly typed:
@model NutricionApp.Models.Platillo
@{
ViewBag.Title = "Create";
Model.ListadeIngredientes = new List<NutricionApp.Models.ListaIngredientes>();
}
<h2>Create</h2>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Platillo</legend>
<div class="editor-label">
@Html.LabelFor(model => model.NombrePlatillo)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.NombrePlatillo)
@Html.ValidationMessageFor(model => model.NombrePlatillo)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.idRestaurante)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.idRestaurante)
@Html.ValidationMessageFor(model => model.idRestaurante)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.DescripcionPlatillo)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.DescripcionPlatillo)
@Html.ValidationMessageFor(model => model.DescripcionPlatillo)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.esAprobado)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.esAprobado)
@Html.ValidationMessageFor(model => model.esAprobado)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.esDisponible)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.esDisponible)
@Html.ValidationMessageFor(model => model.esDisponible)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.precio)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.precio)
@Html.ValidationMessageFor(model => model.precio)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.VigenciaPlatillo)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.VigenciaPlatillo)
@Html.ValidationMessageFor(model => model.VigenciaPlatillo)
</div>
<!--<table>
<tr><th>Nombre</th></tr>
@@foreach (var item in (List<NutricionApp.Models.ListaIngredientes>)Session["Lista"])
{
<tr>
<p>
<td>@@item.ingrediente.NombreIngrediente</td>
</p>
</tr>
}
</table>-->
@Html.Partial("_Ingredientes", Model.);
<br />
@Html.Partial("_ListaIngredientes", Model.ListadeIngredientes)
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
And in my controller I have this:
//....
public ActionResult _ListaIngredientes()
{
IEnumerable<ListaIngredientes> ListaDemo = new List<ListaIngredientes>();
return View(ListaDemo);
}
public ActionResult _Ingredientes()
{
return View(db.Ingredientes.ToList());
}
In this case, db.Ingredients.ToList()); returns the data i need to show on the partial view. Problem is, when I try to display said list in my view, it tells me I have to pass a IEnumerable model corresponding to my view...
If I access the PartialView from an URL, it shows me the data correctly. However if i try to do this from inside a View, it passes the Model it's currently using due to being strongly-typed. How can I pass the model i need (the list of my ingredients table, db.Ingredientes.ToList());