我的控制器代码就像我将数据作为
返回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编号,而不是视图端仅显示文本的编号。
请看这个截图:
答案 0 :(得分:1)
LabelFor
帮助器方法使用属性名称或DisplayName属性呈现标签元素(如果它用于装饰属性)。
如果要打印属性的值,可以使用DisplayFor
辅助方法。
@Html.DisplayFor(model => model.First().StudentRequestId)