@using System.Data@model DataTable@foreach (var row in Model.Rows){ @row[] // how do you cast this to a object?} 如何使用Razor语法将@row转换为对象? 你可以编写常见的C#代码: @foreach (YourType row in Model.Rows){ ...
@using System.Data @model DataTable @foreach (var row in Model.Rows) { @row[] // how do you cast this to a object? }
如何使用Razor语法将@row转换为对象?
你可以编写常见的C#代码:@foreach (YourType row in Model.Rows) { ... }
要么
@foreach (var row in Model.Rows) { YourType casted = (YourType)row; ... }
或者如果您不确定它是否可浇铸:
@foreach (var row in Model.Rows) { YourType casted = row as YourType; if (casted != null) { ... } }