我试图添加一个字典属性在我的模型类中有一个键值对的集合列表之一。但是,我不知道如何用{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