مرجع تخصصی برنامه نویسان

انجمن تخصصی برنامه نویسان فارسی زبان

کاربر سایت

akbaraliyari

عضویت از 1394/11/20

نمایش تصویر در Razor

  • دوشنبه 23 بهمن 1396
  • 15:27
تشکر میکنم

سلام دوستان

من در جدول پایگاه داده تصاویر رو به صورت باینری ذخیره کردم

چطوری میتونم توmvc razor لیست عکسها رو نمایش بدم

پاسخ های این پرسش

تعداد پاسخ ها : 1 پاسخ
کاربر سایت

ایمان مدائنی

عضویت از 1392/01/20

  • دوشنبه 23 بهمن 1396
  • 16:22
public ActionResult GetImage(int id)
{
    byte[] imageData = storeRepository.ReturnImage(id);

    //instead of what augi wrote using the binarystreamresult this was the closest thing i found so i am assuming that this is what it evolved into 
    return new FileStreamResult(new System.IO.MemoryStream(imageData), "image/jpeg");
}

//in my repository class where i have all the methods for accessing data i have this

public byte[] ReturnImage(int id)
{
    // i tried his way of selecting the right record and preforming the toArray method in the return statment 
    // but it kept giving me an error about converting linq.binary to byte[] tried a cast that didnt work so i came up with this
    byte[] imageData = GetProduct(id).ProductImage.ToArray();
    return imageData;
}

<image src='/store/getimage/<%= Html.Encode(Model.productID) %>' alt="" />

کاربرانی که از این پست تشکر کرده اند

هیچ کاربری تا کنون از این پست تشکر نکرده است

اگر نیاز به یک مشاور در زمینه طراحی سایت ، برنامه نویسی و بازاریابی الکترونیکی دارید

با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)