我試圖添加一個字典屬性在我的模型類中有一個鍵值對的集合列表之一。但是,我不知道如何用{get; set;}語法表示這是一個模型屬性,而不是一個簡單的字段。在ASP.NET MVC中聲明初始化字典模型屬性的語法?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace ContosoUniversity.Models
{
public class Profile
{
//classNameID or ID is interpreted by EF as PK.
public int ID { get; set; }
public string UserName { get; set; }
public string Age { get; set; }
public string Location { get; set; }
public string Gender { get; set; }
//How to declare this property with get, set and initialized key/val pairs?
public string Dictionary<string, string> ProfileDetails =
new Dictionary<string, string>()
{
{"HighSchool", ""},
{"UndergraduateSchool", ""},
{"GraduateSchool", ""},
}
}
}
噢非常感謝你,忘記了一切都是「班級」甚至是模特班! – jerryh91 2015-03-25 03:33:35