Images aren't uploaded in my table despite them seemingly being added in the view. Keeps showing the default image in view

13 hours ago 1
ARTICLE AD BOX
@using (Html.BeginForm("SpremiPodatke", "Zaposleni", FormMethod.Post, new { enctype = "multipart/form-data" })) { <div> <span>Slika</span> @Html.TextBoxFor(model => model.s, new { @class="form-control", type = "file" }) </div> <button type="submit">Dodaj</button> })

This is what I have in my view for adding (the image part specifically):

<td> @if (x.Slika != null && x.Slika.Length > 0) { <img id="slikazaposleni" style="width:200px; height:200px;" src="@Url.Action("GetImage", new { Id = x.Id })" /> } else { <img id="slikazaposleni" style="width:200px; height:200px;" src="~/Content/img/teee.jpg" /> } </td>

And this is in the view for the view of the actual table itself. No matter what I do this else happens and instead of showing the image I added in my view for adding it instead always shows the default image in the else. Deleting the else just makes it so there's no image in the table at all.

if (model.s == null) { zaposleni.NazivSlike = null; zaposleni.TipSlike = null; zaposleni.Slika = null; } else { zaposleni.NazivSlike = model.s.FileName; zaposleni.TipSlike = model.s.ContentType; byte[] slika = new byte[model.s.ContentLength]; model.s.InputStream.Read(slika, 0, model.s.ContentLength); zaposleni.Slika = slika; } ctx.zaposlenis.Add(zaposleni); ctx.SaveChanges(); return RedirectToAction("Index");

This is the controller:

public ActionResult GetImage(int Id) { Zaposleni zaposleni = ctx.zaposlenis.Where(x => x.Id == Id).FirstOrDefault(); return File(zaposleni.Slika, zaposleni.TipSlike); }

Please tell me what I am doing wrong. I am losing my mind.

Read Entire Article