Dodanie Zdjęć produktów

0

Witam mam problem z wyświetleniem zdjęć w widoku listy produktów.

W encji Product zdjęcie określa zmienna public string Image{get ; set;}.Gdy dodaje nowy produkt do bazy,wybieram zdjęcie z komputera.Nazwa zdjęcia zapisywana jest w bazie,a w
w widoku index wyświetla mi po prostu biały kwadracik :D

Może coś z tym .first() jest nie tak,ale nie mogłem inaczej bo mam tutaj IPageList i mi krzyczy :
PagedList.IPagedList<Hurtownia.Models.Product>' does not contain a definition for 'Image' and no extension method 'Image' accepting a first argument of type 'PagedList.IPagedList<Hurtownia.Models.Product>' could be found (are you missing a using directive or an assembly reference?

ProductController metoda Create.

 

 [Authorize]
        public ActionResult Create()
        {
            ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name");

            return View();

        }

        // POST: /Product/Create
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "Id,Description,Name,Price,Quantity,CategoryId")] Product product)
        {

            ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name", product.CategoryId);
            try
            {
                HttpPostedFileBase file = Request.Files["imageFile"];
                if (file != null && file.ContentLength > 0)
                {
                    product.Image = file.FileName;
                    file.SaveAs(HttpContext.Server.MapPath("../Images/") + product.Image);
                }

                db.Products.Add(product);
                db.SaveChanges();
                return RedirectToAction("Index");

            }
            catch
            {
                ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name", product.CategoryId);
                return View(product);
            }
        }



Cześć widoku Create

 

@model Hurtownia.Models.Product

@{
    ViewBag.Title = "Create";
}

<h2>Create</h2>


@using (Html.BeginForm("Create", "Product", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    @Html.AntiForgeryToken()
    
    <div class="form-horizontal">
        <h4>Product</h4>
        <hr />
        @Html.ValidationSummary(true)


        <div class="form-group">
            @Html.LabelFor(model => model.Image, new { @class = "control-label col-md-2" })
            <div class="editor-field">
                <input type="file" name="imageFile" size="23" accept="gif|jpg|png"/>
                @Html.ValidationMessageFor(model=>model.Image)
            </div>
        </div>

Część widoku index(lista produktow)

 

@model PagedList.IPagedList<Hurtownia.Models.Product>
@using PagedList.Mvc;
@using PagedList;
<link href="~/Content/PagedList.css" rel="stylesheet" type="text/css" />

@{
    ViewBag.Title = "Products";
    
}

<div class="page-header">
    <h2>Products</h2>

    <p>
        @Html.ActionLink("Create New", "Create")
    </p>
</div>
@using (Html.BeginForm("Index", "Product", FormMethod.Get))
{
    <p>
        Find by name: @Html.TextBox("SearchString", ViewBag.CurrentFilter as string)
        <input type="submit" value="Search" />
    </p>
}

<table class="table">
    <tr>
    <th>
        Image
    </th>
    <th>
        @Html.ActionLink("Name", "Index", new { sortOrder = ViewBag.NameSortParm, currentFilter = ViewBag.CurrentFilter })
    </th>

    <th>
        @Html.ActionLink("Description", "Index", new { sortOrder = ViewBag.DateSortParm, currentFilter = ViewBag.CurrentFilter })
    </th>
    <th>
        Price
    </th>
    @if (User.IsInRole("Admin"))
    {
        <th>
            Ilosc
        </th>
    }

    <th>
        Category
    </th>


</tr>


    @foreach (var item in Model)
    {
        <tr>

            <td>

                <div class="display-label">Image</div>
                <div class="display-field">


                @Html.DisplayFor(model => item.Image)
                <img src="../../Images/@Model.First().Image" alt="" height="100px" width="100px" />


                </div>
0

I ktoś coś wie ? bo nadal nie moge wpaść na rozwiązanie :(

0

Czemu nie weźmiesz tam @item.Image ?

0

akurat to nic nie zmienia ;p

0

To pokaż jeszcze akcje Index, bo rozumiem że to tam się wywala?

0

Właśnie o to chodzi,że nic się nie wywala po prostu zdjęć nie wyświetla i nie wiem czemu :D Sorry jeśli zle napisałem.

0

Sprawdź w przeglądarce jaką ścieżkę dostają te zdjęcia.

Spróbuj tak

<img src="../../Images/@(item.Image)" alt="" height="100px" width="100px" />
0

tak wygląda strona z listą produktów.

0

Sprawdź mojego wcześniejszego edita.
Nie wiesz jak sprawdzić ścieżkę jaką otrzymuje obrazek w przeglądarce?

0

No to co podałeś dalej to samo. Ścieżka jest dobra 3 zdjęcia pokazują folder w którym trzymam zdjęcia.

0

I jak skopiujesz adres obrazka, wkleisz do paska przeglądarki to obraz się pokazuje?

0

coś się z przeglądarka stało ,zmieniłem na mozille i się zdjęcia pojawiły :D

0

IE i opery,ale z opera ogólnie ostatnio mam problem . Dzięki za pomoc ;)

1 użytkowników online, w tym zalogowanych: 0, gości: 1