I want to display a partial view and populate it with the model Sale. Currently this is my (non-working) code:
Home view:
@foreach (Webshop.Models.Sale item in Model) {
@Html.Partial("_Sale", (Webshop.Models.Sale) item)
}
Partial:
@model Webshop.Models.Sale
<div class="sale">
<h5>@Html.ActionLink(item.Product.Name, "Details", "Product", new { id = item.ID }, null)</h5>
</div>
I get a compilation error saying item doesn't exist. If I name it model, it doesn't exist either.
Change your partial code. item should be Model:
@model Webshop.Models.Sale
<div class="sale">
<h5>@Html.ActionLink(Model.Product.Name, "Details", "Product", new { id = Model.ID }, null)</h5>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With