I have an image table with several images and the image type is varchar(max)
Model:
namespace EquipmentInventory.Models
{
using System;
using System.Collections.Generic;
public partial class Image
{
public int ImageID { get; set; }
public string ImageName { get; set; }
public string ImageData { get; set; }
public Nullable<int> EquipmentID { get; set; }
public virtual Equipment Equipment { get; set; }
}
}
View:
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.ImageName)
</td>
<td>
@Html.DisplayFor(modelItem => item.ImageData)
</td>
<td>
@Html.DisplayFor(modelItem => item.Equipment.Company)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.ImageID }) |
@Html.ActionLink("Details", "Details", new { id=item.ImageID }) |
@Html.ActionLink("Delete", "Delete", new { id=item.ImageID })
</td>
</tr>
Controller:
namespace EquipmentInventory.Controllers
{
public class ImagesController : Controller
{
private InventoryEntities db = new InventoryEntities();
public ActionResult Index()
{
var images = db.Images.Include(i => i.Equipment);
return View(images.ToList());
}
When I run this in the ImageData field I get a HUGE string of random characters rather than the actual image.