How to show image from database table in ASP.NET MVC

April 05, 2016 0 Comments

In this article i will show you, How to display image from database in ASP.NET MVC. To do this task, we will use <img /> tag in view section. First of all, Create a connection with the database using Entity Data model (Learn How to use ADO.NET Entity Data Model). In the controller action method pass the list of data to the view. Like that:

 private DatabaseEntities db = new DatabaseEntities();

        // GET: Home
        public ActionResult Index()
            return View(db.Employees.ToList());

In the View section: 

@model IEnumerable<WebApplication23.Employee>

@foreach (Employee item in Model)
<img src="@Url.Content(item.Database_Picture_column)" width="100" height="100" />


Jacob Lefore

Some say he’s half man half fish, others say he’s more of a seventy/thirty split. Either way he’s a fishy bastard. Google