这是我的viewtrainees.cshtml.cs文件片段,其中包含数组代码:
public class viewTraineeModel : PageModel
{
public string[] traineeinfo { get; set; }
(...)
在我的OnGet()中:
string[] traineeinfo = new string[Convert.ToInt32(countnum)];
int i = 0;
while (trainees.Read())
{
traineeinfo[i] = trainees["t3_win"].ToString();
i++;
}
所以一切都在我的数组中进行了很好的设置,我什至在.cs文件中进行了测试。但是,当我传递数组或认为将数组传递给视图时,它总是给我内部错误。
我已经尝试了viewtrainees.cshtml文件:
@Model.traineeinfo[0]
我得到NullReferenceException:对象引用未设置为对象的实例。错误。
我的代码的head元素看起来像这样。
@page
@model T3_Landing.Pages.viewTraineeModel
@{
ViewData["Title"] = "View Trainees";
string[] traineeinfo = Model.traineeinfo as string[];
}
我已经尝试过,并且没有重新初始化字符串数组,如上所述。我真的希望它能正常工作。
请注意,我可以使用@ Model.examplestring传递常规字符串,但不能传递数组,列表或对象。