Hi,
Iam using MVc4,with EF ,iam not able to display the image in my webgrid ,but the product name is displaying.IN sql server the productimage column is varbinary(max). when iam running this code iam getting boxes,near that iam getting the text "System.Byte[],sqlserver image",Pls help me out
Model code:
public partial class Product
{
public string ProductName { get; set; }
public byte[] PRoductImage { get; set; }
}
Context Class:
public Databases()
: base("name=Databases")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public DbSet<Customer> Customers { get; set; }
public DbSet<Order> Orders { get; set; }
public DbSet<Product> Products { get; set; }
Controller Code:
public class Default1Controller : Controller
{
public Customer t { get; set; }
public Order t1 { get; set; }
public Product t2 { get; set; }
//
// GET: /Default1/
Databases db = new Databases();
public ActionResult Index()
{
return View(db);
}
}
View Code:
@model MyAPP.Models.Databases
@{
ViewBag.Title = "Index";
var grid = new WebGrid(source: Model.Products, rowsPerPage: 5);
}
@grid.GetHtml(columns: grid.Columns( grid.Column("ProductName", "ProductName"),grid.Column("PRoductImage", header: "Image", format: @<img src="@item.PRoductImage" alt="@item.PRoductImage" width="200px" height="100px" /> ) ) )
<input type="submit" value="insert" />
}