这可能吗?在遍历列表时,在 for each 循环中存储数据时,我无法将其实际类用作变量类型。
@using MyFirstWebApplication.Models.Student
@model IEnumerable<MyFirstWebApplication.Models.Student>
@{
ViewBag.Title = "Title";
}
<h2>This is a heading</h2>
@foreach (Student student in Model)
{
<h2>Student Name: @student.FirstName @student.LastName</h2>
}
只有当 foreach 循环中的变量类型为 'var' 时,代码才会编译
最佳答案
您的@using 语句看起来不正确。假设类的全名是MyFirstWebApplication.Models.Student,using语句应该是:
@using MyFirstWebApplication.Models
关于c# - 在 cshtml View 中导入 c# 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30015965/