I dont know much about asp.net MVC / Razor, but there is an important difference between your 2 code samples.
public string Description { get; set; }
Creates a property, once compiled, there is a generated private field in the class, with get/set methods that access the field. A property declared with {get;set;} is the equivalent of:
private string _description;
public string Description
{
get
{
return _description;
}
set
{
this._description = value;
}
}
However the following:
public string Description;
Creates a simple public field.
My guess is that razor uses reflection to get values from the ViewModel, and it probably looks for a property, not a field. So it determines that the property does not exist, hence returning null
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…