更新时间:2022-11-27 21:38:03
嗯,实际上,再三考虑一下,仔细检查sublegerType_Id?我不确定它应该是Id.我认为它必须是实际的对象.
hmm, actually, on second thought, double check sublegerType_Id? I'm not sure it should be the Id. I think it needs to be the actual object.
例如,这不起作用(默认为第一项)
for example, this doesnt work (it defaults to the first item)
List<Tuple<string, string>> NumberList = new List<Tuple<string, string>>();
for (int i = 0; i < 5; i++)
{
NumberList.Add(new Tuple<string, string>(i.ToString(),i.ToString()));
}
NumberSelectList = new SelectList(NumberList,"2");
但这可以正常工作(默认为(4,4)的选定项)
but this works okay (it defaults to the selected item of (4,4))
List<Tuple<string, string>> NumberList = new List<Tuple<string, string>>();
Tuple<string, string> selectedObject = new Tuple<string, string>("-1","-1");
for (int i = 0; i < 5; i++)
{
if (i == 4)
{
selectedObject = new Tuple<string, string>(i.ToString(), i.ToString());
NumberList.Add(selectedObject);
}
else
NumberList.Add(new Tuple<string, string>(i.ToString(), i.ToString()));
}
NumberSelectList = new SelectList(NumberList, selectedObject);