@using System.Data
@model DataTable
@foreach (var row in Model.Rows)
{
@row[] // how do you cast this to a object?
}
How do you cast @row to an object in Razor syntax?
You can just write common C# code:
@foreach (YourType row in Model.Rows)
{
...
}
or
@foreach (var row in Model.Rows)
{
YourType casted = (YourType)row;
...
}
or if you're not sure if it's castable:
@foreach (var row in Model.Rows)
{
YourType casted = row as YourType;
if (casted != null)
{
...
}
}
I happened upon this problem today. The solution I used was using parenthesis:
@((YourType) row)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With