Displaying database data table in MVC

Made a change of solution: I am trying to display a html data table. In my controller, I run the object as null and then pass the object as a reference to update the object based on information in the DB, a custom 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 when the information is in a data object using a similar route, it is all in a 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 .... as I had the table attribute set to runat = server which gave me the error. Don't know why, but he did

0


source to share


2 answers


I'm not sure why you are avoiding the ViewData.Model. There is no reason I can see in this case why:

 ViewData["data"] = data;

      

preferable



 ViewData.Model = data;

      

If you were using a strongly typed View page, you could avoid having to use a model. Then you can simply do:

 <% foreach (dataob m in ViewData.Model) { %>
    <tr> 
        <td><%= m.Id %></td>
        <td><%= m.user %></td>
        <td><%= m.Date %></td>
    </tr>
 <% } %>

      

+5


source


Try:



<% foreach (dataob m in (IEnumerable<dataob>) ViewData["data"]) { %>

      

0


source







All Articles