79269708

Date: 2024-12-10 20:33:15
Score: 0.5
Natty:
Report link

The issue is solved. I added a new Action method in Controller:

public ActionResult GetImage(int id)
{
    string conStr = "Data Source=.\\SQLEXPRESS; Initial Catalog=Nettbutikk; Integrated Security=True";
    SqlConnection con = new SqlConnection(conStr);
    con.Open();

    SqlDataAdapter dataAdapter = new SqlDataAdapter(new SqlCommand("select * from products", con));
    DataSet dataSet = new DataSet();
    dataAdapter.Fill(dataSet);

    
    Byte[] data = new Byte[0];
    data = (Byte[])(dataSet.Tables[0].Rows[0]["picture"]);
       
    return File(data, "image/jpg");
}

and then calling this method in View:

<img src="@Url.Action("GetImage", new { id = 1 })" alt="Northern Lights" width="600" height="400">
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: javed