我的模型有很多属性
public class Task {
public string Key { get; set; }
public string Title { get; set; }
public string Description { get; set; }
....
}
我需要在 View 中创建一个表来列出任务的所有属性。
已经问了同样的问题,但我不想使用 ViewData:Looping through view Model properties in a View
有什么想法吗?
最佳答案
这对你有用吗?
@foreach(var task in Model) {
<tr>
@foreach(var property in typeof(Task).GetProperties()) {
<th>@(property.GetValue(task, null))</th>
}
</tr>
}
关于c# - 在 MVC View 中使用 Razor 循环模型属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37058536/