无法从控制器检索数据

Not able to retrieve data from controller

我的控制器代码就像我返回数据一样

public ActionResult StudentDashboard(int? page)
{    
    ViewBag.StudentRequest = GetData.Tables[0].AsEnumerable().Select(t => new
                                {
                                    StudentRequestId = t.Field<int>("StudentRequestId"),
                                    ClassName = t.Field<string>("ClassName"),
                                    CreatedOn = t.Field<DateTime>("CreatedOn"),
                                    Location = t.Field<string>("Location"),
                                    PaymentMethod = t.Field<string>("PaymentMethod"),
                                }).ToList().ToPagedList(page ?? 1,1);

    return View(db.StudentRequests.Where(x => x.RegistrationId ==  registrationid).ToList().ToPagedList(page ?? 1, 3));
}

另外,如何在此代码中将内部联接添加为 class table?

db.StudentRequests.Where(x => x.RegistrationId ==  registrationid)
                  .ToList()
                  .ToPagedList(page ?? 1, 3)

并且在视图方面我将代码编写为

@using PagedList;
@using PagedList.Mvc;
@model IPagedList<Student_Tutor.Models.StudentRequest>

   @if (ViewBag.StudentRequest != null)
    { 
      var StudentRequestId = (int)Model.First().StudentRequestId;// Here I am able to get the StudentRequestId 
      var StudentRequestTimecount = StudentRequestTime.Where(d => d.StudentRequestId == StudentRequestId).ToList();
      var TutorStudentRequestcount = TutorStudentRequest.Where(d => d.StudentRequestId == StudentRequestId).ToList();
      @Html.LabelFor(model => model.First().StudentRequestId)// here only text is displaying as StudentRequestId
      @Html.DisplayNameFor(Model => Model.First().CreatedOn)//here only text is diplaying as created on
}

如何在

获取 StudentRequestId 记录而不是仅文本
@Html.LabelFor(model => model.First().StudentRequestId)

通过这段代码,我无法获得 StudentRequestId 的 ID 编号,而不是视图端仅显示文本的编号。

请看这张截图:

LabelFor 帮助器方法使用 属性 或 DisplayName 属性 的名称渲染标签元素(如果它用于装饰 属性)。

如果你想打印 属性 的值,你可以使用 DisplayFor 辅助方法。

@Html.DisplayFor(model => model.First().StudentRequestId)