I'm trying to display a byte[] image from database in a .NET MVC WebGrid Column. I`m doing the following steps
(EF Model - Articulos)
[Key]
public int id_Art { get; set; }
public int id_Pro { get; set; }
[StringLength(1)]
public string tipo_Pro { get; set; }
[Required]
[StringLength(50)]
public string nombre_Pro { get; set; }
[Required]
[StringLength(100)]
public string descripcion_Pro { get; set; }
public byte[] imagen_Pro { get; set; }
[Required]
public decimal? precio_Pro { get; set; }
public int? estatus_Pro { get; set; }
(Controller)
public List<articulos> cargarArticulos(string search, string sort, string sortdir, int skip, int pageSize, out int totalRecord)
{
using (DbModel db = new DbModel())
{
var v = (from a in db.articulos
where
a.tipo_Pro.Contains(search) ||
a.nombre_Pro.Contains(search) ||
a.descripcion_Pro.Contains(search)
select a
);
totalRecord = v.Count();
v = v.OrderBy(sort + " " + sortdir);
if (pageSize > 0)
{
v = v.Skip(skip).Take(pageSize);
}
return v.ToList();
}
}
(View)
<div>
@grid.Table(
tableStyle: "table table-responsive table-bordered",
headerStyle: "webgrid-header",
footerStyle: "webgrid-footer",
alternatingRowStyle: "webgrid-alternating-row",
rowStyle: "webgrid-row-style",
columns: grid.Columns(
grid.Column(columnName: "imagen_Pro", header: "IMAGEN", format: ),
grid.Column(columnName: "tipo_Pro", header: "TIPO"),
grid.Column(columnName: "nombre_Pro", header: "NOMBRE"),
grid.Column(columnName: "descripcion_Pro", header: "DESCRIPCION"),
grid.Column(columnName: "precio_Pro", header: "PRECIO"),
grid.Column(header: "⇨", format: (item) => Html.ActionLink("Ver", "Ver", new { }))
)
)
Everything else works just fine, i'm succesfully retrieving the list from the controller, and it displays into the Webgrid, the only problem is to display the byte[] image stored in my database, i don´t know how to convert it to base64 before to display in the webgrid or simply adding the righ format in the column. I've been working on this for hours, please help.
grid.Column(columnName: "imagen_Pro", header: "IMAGEN", format: ),