I would like to add an extension method for the html helper to customize a table, i add this method:
public static class HtmlElements
{
public static string Table(this HtmlHelper ht, string classe)
{
var table = new HtmlTable();
table.Attributes.Add("class", classe);
return table.InnerHtml;
}
}
When i'd like to use it like this
@using(@Html.Table("table_data")){
}
i have an error which indicates that i have to convert a string to IDisposable type.
- What are the reasons of this error?
- How can i fix it?
Edit
the full view's code :
using(var table = @Html.Table("table_data")){
<tr>
<th>Description</th>
<th>Client</th>
<th>Statut du client</th>
<th>Etat de test</th>
<th></th>
</tr>
for (int i = Model[2] - 5; i < Model[2]; i++)
{
if(i < Model[1].Count)
{
<tr style="font-size: 12px; padding:0px; ">
<td>@Model[0][i].PDescription</td>
<td>@Model[0][i].Nom_client</td>
<td>@Model[0][i].Statut_client</td>
<td style="color:red">@Model[1][i]</td>
<td>
@Model[0][i].Statut_client
</td>
</tr>
}
}
}
using? you can move creating html to your helper and return string with generated html, without object