locked
Image not displayed when redirected to the file RRS feed

  • Question

  • User1450159794 posted

    I have ASP.NET webpages project which has 2 cshtml (ListItems.cshtml & EditItem.cshtml)files.

    ListItems.cshtml --> List items from database with the image associated with the Item.

    Each Line of list has a EDIT button which directs to EditItem.cshtml file with the ProductID.

    When EditItem.cshtml is run in browser (with hard coded ProductId value (eg: 3)) --> It displays The Image properly with the bellow code

                                                                                                                                              (<div class="result"><img src="@imagePathZ" alt="img" /></div>)

    But

    When it is redirected from ListItems.cshtml --> EditItem.cshtml doesnt display the image (the image exist in the folder )

    It cant be the 

    var ProductId = UrlData[0]; 

    because ItemName is also retrieved with  ProductId  & correct itemName is displayed.

    Here is the code of EditItem.cshtml 

    ---------------------------------------

    @{
    WebImage photo = null;
    var newFileName = "";
    var imagePathZ = "";

    var db = Database.Open("InventoryDB-B");
    var ProductId = UrlData[0];
    //int ProductId = 3;
    //int ProductId = Int32.Parse(ProductId2);

    var itemNameZ = "";

    if (IsPost)
    {
          photo = WebImage.GetImageFromRequest();

          if (photo != null)
          {
               newFileName = photo.FileName;

               imagePathZ = @"images\" + newFileName;

               photo.Save(@"~\" + imagePathZ);

               itemNameZ = Request["itemNameZ"];

           }
    }

    else

    {
            var selectQueryString = "SELECT * FROM InventoryTBLB WHERE itemID=@0";
            var row = db.QuerySingle(selectQueryString, ProductId);
            itemNameZ = row.itemName;
            imagePathZ = row.imagePath;
    }


    }

    <!DOCTYPE html>
    <html>

    <head>
    <title>Edit Item</title>

    </head>

    <body>
    <!----- Item properties -->
    <form action="" method="post">
    <fieldset>
    <div>
    <label>Item NameDDD:</label>
    <input name="itemNameZ" type="text" size="50" value="@itemNameZ" />

    </div>
    <input type="submit" value="SaveMe" />
    </fieldset>
    </form>


    <!----- Image Upload -->
    <form action="" method="post" enctype="multipart/form-data">
    <fieldset>
    <legend> Upload Image </legend>
    <label for="Image">Image</label>
    <input type="file" name="Image" size="65" />
    <br />
    <br />
    <input type="submit" value="UploadMe" />


    </fieldset>
    </form>


    <h1>Uploaded Image</h1>
    @{
          <div class="result"><img src="@imagePathZ" alt="img" /></div>
          <p>@imagePathZ</p>
          <p>@ProductId</p>
    }

    </body>

    </html>

    -----------------------------------------

    When we set 

    int ProductId = 3; in EditItem.cshtml it displays the image correctly.

    When redirected from ListItem.cshtml page (with the itemID) Image doesnt display in EditItem.cshtml (image exist in the correct folder)

    Can someone help ????

    Wednesday, May 17, 2017 1:29 PM

All replies

  • User-846834550 posted

    When we set 

    int ProductId = 3; in EditItem.cshtml it displays the image correctly.

    When redirected from ListItem.cshtml page (with the itemID) Image doesnt display in EditItem.cshtml (image exist in the correct folder)

    Can someone help ????

    Using F12 developer tools to debug your webpage. Please refer https://msdn.microsoft.com/en-us/library/gg699337(v=vs.85).aspx.

    Monday, May 29, 2017 1:39 AM