Asp.net mvc 2 空列表ASP.NET MVC2的模板/数据/模型上下文

Asp.net mvc 2 空列表ASP.NET MVC2的模板/数据/模型上下文,asp.net-mvc-2,Asp.net Mvc 2,我已经创建了一个视图,用于添加/删除列表中的项目。我试图动态地处理添加/删除操作,但我不清楚当列表为空时如何获得正确的模板上下文 该视图基于: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Service.Cms.ListItems; namespace Bcp.Service.Cms.Documents { public class Tasting

我已经创建了一个视图,用于添加/删除列表中的项目。我试图动态地处理添加/删除操作,但我不清楚当列表为空时如何获得正确的模板上下文

该视图基于:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Service.Cms.ListItems;

namespace Bcp.Service.Cms.Documents
{
    public class Tasting //: Document
    {
        public Tasting() { }

        public List<DocumentListItem> relatedCrap { get; set; }
    }
}
为了保存列表项,每个属性都需要在前面加上
tastingInfo.relatedDocs.#PROPERTYNAME.#

但是,如果加载视图时列表为空,我不知道如何访问该上下文。有人有什么想法吗?

我最终为
列表创建了一个名为DocumentListDisplay的显示模板,其中包含以下内容:

<input type="hidden" value="<%: ViewData.TemplateInfo.HtmlFieldPrefix %>" />

在同一个模型上调用
EditorFor()
之前,我只需在视图中调用此模板。这很麻烦,但它提供了模板上下文,而不必硬编码任何内容或向ViewData添加任何内容

<input type="hidden" value="<%: ViewData.TemplateInfo.HtmlFieldPrefix %>" />