我有一个具有[key]
属性的 ViewModel,我想从该视图模型的实例中获取它。
我的代码看起来像这样(虚构模型)
class AddressViewModel
{
[Key]
[ScaffoldColumn(false)]
public int UserID { get; set; } // Foreignkey to UserViewModel
}
// ... somewhere else i do:
var addressModel = new AddressViewModel();
addressModel.HowToGetTheKey..??
所以我需要UserID
从 ViewModel 中获取(在这种情况下)。我怎样才能做到这一点?