What I try is add some dummy records which I want to use in an ASP.NET MVC 3 view to provide data for some experiments. I try this:
var dummyData = new[]
{
new {Row = 1, Col = 1, IsRequired = true, QuestionText = "Yes?", FieldValue = "int"},
new {Row = 1, Col = 2, IsRequired = true, QuestionText = "Yes?", FieldValue = "int"},
new {Row = 2, Col = 1, IsRequired = true, QuestionText = "No?", FieldValue = "string"},
new {Row = 3, Col = 1, IsRequired = false, QuestionText = "No?", FieldValue = "string"}
}.ToList();
ViewBag.Header = dummyData;
However when I try to use the data in my view :
@{
foreach (var item in ViewBag.Header)
{
<tr><td>@item.QuestionText</td><td>@item.FieldValue</td></tr>
}
}
I get this error - 'object' does not contain a definition for 'QuestionText'
. I'm thinking that there's something wrong with the way I create the list but not 100% sure.