无法从控制器

时间:2017-11-06 14:46:30

标签: asp.net-mvc asp.net-mvc-4 asp.net-mvc-3

我的控制器代码就像我将数据作为

返回
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));
}

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

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编号,而不是视图端仅显示文本的编号。

请看这个截图:

enter image description here

1 个答案:

答案 0 :(得分:1)

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

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

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