0

Can I use HtmlTable class in asp.net MVC?

I created HtmlTable object in Controller class:

 var Table1 = new HtmlTable();

How to view it in the web page?

When I use:
PlaceHolder1.Controls.Add(Table1); in Controller class
and
<asp:placeholder id="PlaceHolder1" runat="server"></asp:placeholder> in index.cshtml
I have warning "Unrecognized namespace 'asp'"
How bind PlaceHolder1 from Controller class and placeholder id="PlaceHolder1" from View?

Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
Olena
  • 293
  • 3
  • 6
  • 12

1 Answers1

0

You can't use the asp placeholder control with ASP.NET MVC. Almost all controls require view state, which ASP.NET MVC doesn't support.

Paul Welbourne
  • 1,063
  • 10
  • 16
  • msdn: "The HtmlHelper class is designed to generate UI. It should not be used in controllers or models." But I need something for work in Controller. – Olena May 23 '13 at 11:05
  • What do you want the placeholder for? Do you need to set the tables visibility or some other properties based on some property in the controller? – Paul Welbourne May 23 '13 at 11:12
  • I need create dynamic table. All information about raws and columns are in lists of objects. I used: for example `@Html.Raw(ViewBag.htmlFirstColumn)` – Olena May 23 '13 at 11:24
  • This is best dealt with in the View and not the Controller. I guess you are passing a collection of items in your model to render in the table. You can construct your table in the View by using razor syntax or by using a HtmlHelper, passing in the parameters you need to the Helper method call. – Paul Welbourne May 23 '13 at 11:28