我在獲取和設置值時遇到問題,因爲我在代碼中引入了第三方面。試圖獲取/設置記錄
以前我會做這個拿到/在記錄設置:
public virtual string MyString { get; set;}
,然後在我的部分:
public string MyString
{
get { return Record.MyString; }
set { Record.MyString = value; }
}
和NHibernate會保存在DB我的價值觀(顯然我的其他爲簡潔起見,此處不提供代碼)。
現在我正在嘗試做一個帶有列表的複選框。我有這樣一個複選框:。
public class MyPart : ContentPart<MyPartRecord>
{
public MyPart()
{
MyList = Enum.GetValues(typeof(MyEnum))
.Cast<MyEnum>().Select(x =>
{
return new SelectListItem { Text = x.ToString().ToUpper(),
Value = ((int)x).ToString() };
}).ToList();
}
public IList<SelectListItem> MyList { get; set; }
private string myCheckBox;
// Record class contains the following commented code:
// public virtual string MyCheckBox { get; set;}
// Trying to do this now here in MyPart class:
public string MyCheckBox
{
get
{
if (!string.IsNullOrEmpty(myCheckBox))
return myCheckBox;
// Tried the following commented code to get value:
// Record.MyCheckBox = myCheckBox;
return string.Join(",", MyList.Where(x => x.Selected)
.Select(x => x.Value).ToArray());
}
set
{
myCheckBox = value;
// Tried the following commented code to set value:
// Record.MyCheckBox = myCheckBox;
}
}
}
我只是不知道如何在這種情況下,分配值(獲取/設置myCheckBox
到MyCheckBox
它被保存在數據庫中爲空
謝謝在
嘗試'Record.MyCheckBox =值' –
@DStanley我在幾天前試過:) – REMESQ