vendredi 7 août 2015

how can render HtmlTable

i use HtmlTable to create a table . but i get just "System.Web.UI.HtmlControls.HtmlTable" on browser.

in controller :

public ActionResult Index()
   {
       HtmlTable htmlTable1 = new HtmlTable();
       for (int i = 0; i < 2; i++)
       {

           HtmlTableRow rows = new HtmlTableRow();         //a new Row

           for (int j = 0; j < 3; j++)
           {

               HtmlTableCell cell = new HtmlTableCell(); //a new Cell
               cell.InnerHtml = i + "," + j;               //Insert Data into Cell

               cell.Align = "Center";

               cell.BorderColor = "Gray";
               rows.Cells.Add(cell);                       //Attach Cell with Row
           }
           htmlTable1.Rows.Add(rows);                      //Attach Row with Table
       }
       ViewBag.tt = htmlTable1;

       return View();

in view :

<div class="portlet-body">

  @Html.Raw(ViewBag.tt)

 </div>

Aucun commentaire:

Enregistrer un commentaire