Контроллер:
private readonly IApplicationEnvironment _appEnvironment;
public YourController(IApplicationEnvironment appEnvironment)
{
_appEnvironment = appEnvironment;
}
public ActionResult Create()
{
YourModel model = new YourModel();
string path = _appEnvironment.ApplicationBasePath + "\\wwwroot\\Content\\Default"; // получим путь к файловой системе
model.Photo = ImageToByte(path + "\\Image.png");
}
private byte[] ImageToByte(string path)
{
Image image = Image.FromFile(path);
MemoryStream memoryStream = new MemoryStream();
image.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png);
return memoryStream.ToArray();
}
Вьюшка:
@Html.Raw("<img style='width:50px;' src=\"data:image/jpeg;base64," + Convert.ToBase64String(Model.Photo) + "\" />")