我有一系列货架,每个货架都有一系列产品。为了优化重用,我创建了一个部分视图ProductList.ascx,当我遍历货架列表时调用它。在局部视图中,我想为每种类型的产品添加一个Add链接,并且需要Shelf Id来执行此操作。由于部分视图是产品的集合,并且该架子上可能没有产品,我如何在包含Shelf ID的部分中添加添加链接?
父视图:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<ShelfDetail>>" %>
<% foreach (ShelfDetail shelf in Model)
{ %>
<%= Html.Encode(shelf.Name) %>
<%= Html.ActionLink("Delete Shelf", "Delete", "Shelf", new { Id = shelf.Id }, null)%>
<%= Html.ActionLink("Edit Shelf", "Edit", "Shelf", new { Id = shelf.Id }, null) %>
<% Html.RenderPartial("SoupList", shelf.Soups); %>
<% Html.RenderPartial("PieList", shelf.Pies); %>
<p><%= Html.Encode(shelf.Description) %></p>
<% } %>
<% } %>
儿童汤视图(尝试添加路径值,在此处显示“需要货架ID”):
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<SoupList>>" %>
Doors: <%= Html.ActionLink("Add Soup", "Add", "Soup", NEED SHELF ID HERE, null)%>
<% foreach (SoupList soup in Model)
{ %>
<%= Html.Encode(soup.Flavor) %>
<% } %>
答案 0 :(得分:3)
将SoupList的模型类型更改为包含货架ID和汤列表的类型,例如:
public class SoupPresentation
{
public Guid ShelfId { get; set; }
public IEnumerable<SoupList> Soups { get; set; }
}