public class StudentViewModel
{
public Student studentVm { get; set; }
public StudentAdditionalInfo studentAdditionalInfoVm { get; set; }
public int rcImgToProcess { get; set; }
}
studentVm
和studentAdditionalInfoVm
存储我的2个表Student
和StudentAdditionalInfo
的数据,这些数据包含多个记录
rcImgToProcess
存储我从控制器传递的记录计数的数据,因此它只是一个数据(我可以使用ViewBag但出于某种原因我更喜欢将其传递给模型)
<div>
I want the value of [rcImgToProcess] here
</div>
@foreach (var item in Model)
{
<tr>
<td>@item.studentVm.Id </td>
<td>@item.studentVm.StudentCourse</td>
<td>@item.studentAdditionalInfoVm.MotherName</td>
<td>@item.studentAdditionalInfoVm.FatherName</td>
</tr>
}
控制器
int rcImgToProcess = "0";
rcImgToProcess= 1001;
var studentList = from s in student
join st in studentAdditionalInfo on s.Id equals st.Id into st2
from st in st2.DefaultIfEmpty()
select new StudentViewModel {
studentVm = s,
studentAdditionalInfoVm = st,
rcImgToProcess = rcImgToProcess
};
return View(studentList);
如何调用rcImgToProcess
显示在页面的标题部分
答案 0 :(得分:0)
您是否正确引用了视图中的StudentViewModel
?
你应该在文件的顶部有@model <namespaceForStudentViewModel>.StudentViewModel
。
例如@model SampleApplication.ViewModels.StudentViewModel
然后您可以在视图中的任意位置使用<div>@Model.rcImgToProcess</div>