我有一堂课:
public class TaskDiplayModel
{
public int taskId { get; set; }
[DisplayName("Task Description")]
public string description { get; set; }
[DisplayName("Priority")]
public string priority { get; set; }
[DisplayName("State")]
public string state { get; set; }
[DisplayName("Due By")]
public DateTime deadline { get; set; }
[DisplayName("Created By")]
public PersonObject created_by { get; set; }
[DisplayName("Assigned To")]
public PersonObject assigned_to { get; set; }
[DisplayName("Category")]
public string category { get; set; }
[DisplayName("Sub Category")]
public string subCategory { get; set; }
[DisplayName("Created")]
public DateTime createdDate { get; set; }
[DisplayName("Updated")]
public DateTime lastUpdatedDate { get; set; }
[DisplayName("Updated By")]
public PersonObject lastUpdatedBy { get; set; }
}
然后我有另一个从这个类继承的类:
public class TaskModifyModel : TaskDiplayModel
{
public int priorityId { get; set; }
public int stateId { get; set; }
public int categoryId { get; set; }
public int subCategoryId { get; set; }
public SelectList states { get; private set; }
public SelectList priorities { get; private set; }
public SelectList categories { get; private set; }
public SelectList subCategories { get; private set; }
public TaskModifyModel()
{
SetupReferenceData(0);
}
public TaskModifyModel(int taskId)
{
var taskService = new TaskService();
var task = taskService.GetTask(taskId);
}
}
在我的应用程序中,我创建了一个TaskModifyModel
对象。但是,基类中的字符串字段是null
. 我希望它们已经被创建并成为String.Empty
. 但是当我尝试访问它们时出现异常。我错过了什么吗?
顺便说一句,这些是 MVC3 模型......并且类中的代码已被省略,因为我认为这与问题无关。