i'm new to C# and MVC and i need some help. I need to show a datatable with one of the columns being a image. I'm using a image path from a database to get the image from the site. The rest of the columns need to be just plain text. How can i make only the first column use a image tag and the rest just plain text/information?
The controller:
public ActionResult Product()
{
ProductController pc = new ProductController();
DataTable pt = new DataTable("Product Table");
pt = pc.fillProducts();
return View(pt);
}
public class ProductController : DatabaseController
{
public DataTable fillProducts()
{
try
{
string sql = "Select product.image as 'Foto', product.naam as 'Naam', product.prijs as 'Prijs' from product";
MySqlCommand cmd = new MySqlCommand(sql, conn);
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
DataTable products = new DataTable();
da.Fill(products);
return products;
}
catch (Exception e)
{
Console.Write(e);
return null;
}
finally
{
conn.Close();
}
}
}
The view:
<table class="winkelwagen">
<thead>
<tr>
@foreach (System.Data.DataColumn col in Model.Columns)
{
<th>@col.Caption</th>
}
</tr>
</thead>
<tbody>
@foreach (System.Data.DataRow row in Model.Rows)
{
<tr>
@foreach (var cell in row.ItemArray)
{
<td><img src='@cell.ToString()' /></td>
}
</tr>
}
</tbody>
</table>
Thanks in advance!