Reputation: 30364
Made solution change: I am trying to display a html table of data.. In my controller I start an object as null and then pass the object as a reference to update the object based on the info in the DB like so "user control named(Indexcontrol.ascx)":
List<dataob> data = null;
dataManager target = new dataManager();
//pass the parameter to a stored procedure and update it
target.LoadFromDatabase(ref data);
this.ViewData.Model =data;
return View("Index");
I am trying to see how to display a table once the information is in the data object using a similar route all this is in the user control
<tbody >
<% foreach (businesslayer.dataob m in ViewData.Model)
{ %>
<tr>
<td><%= m.ID%></td>
<td><%= m.Date %></td>
<td><%= m.Description %></td>
</tr>
<% } %>
</tbody>
I figured out the problem....since I had the table attribute set to runat=server thats what gave me the error..don't know why but it did
Upvotes: 0
Views: 3069
Reputation: 532435
I'm not sure why you are avoiding the ViewData.Model. There is no reason, that I can see in this case, why:
ViewData["data"] = data;
is preferrable to
ViewData.Model = data;
If you used a strongly typed View page, you could then avoid the need to cast the Model as well. Then you could simply do:
<% foreach (dataob m in ViewData.Model) { %>
<tr>
<td><%= m.Id %></td>
<td><%= m.user %></td>
<td><%= m.Date %></td>
</tr>
<% } %>
Upvotes: 5
Reputation: 32698
Try:
<% foreach (dataob m in (IEnumerable<dataob>) ViewData["data"]) { %>
Upvotes: 0