回答

3

編輯/顯示模板不能很好地與Dictionary<TKey, TValue>工作。就我個人而言,我避免使用這種類型,尤其是與EditorTemplates,因爲模型活頁夾可能是PITA,因此生成correct field names

我建議你定義一個自定義視圖模型:

public class Item 
{ 
    public string Key { get; set; } 
    public string Value { get; set; } 
} 

,然後對您的視圖模型IEnumerable<Item>屬性您定義編輯/顯示模板。它會讓你的生活更輕鬆。然後,剩下的就是將模型屬性(可能是Dictionary<TKey, TValue>)映射到視圖模型屬性。

相關問題