Images not displaying on production server

Jan 21, 2012 at 12:17 AM
Edited Jan 21, 2012 at 1:14 AM

Hi, 

I have created a spice store by following the MvcMusicStore 2.0 tutorial.

I have changed the path name "/Content/Images/.." to "Content/Images" in SQL Server Management Studio.

After making that change the products image on the homepage can be displayed. But if one browses to the variety section;

http://58.27.26.114/1072008030072/Store/Browse?Variety=Spices

Its returning an invalid image thumbnail.

Are there any proper syntax that should be replaced in the Store View or Store Controller?

Thank you for looking into this.

This is the controller from StoreController.cs

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

        public ActionResult Browse(string variety)
        {
            //Retrieve Variety and its Associated Products from database
            var varietyModel = storeDB.Varieties.Include("Products")
                .Single(v => v.Name == variety);

            return View(varietyModel);
        }

This is the view from Browse.cshtml

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

 

<div class="variety"> <h3><em>@Model.Name</em> Products</h3>

 <ul id="product-list"> 

@foreach (var product in Model.Products)  

{    

 <li>    

<a href="@Url.Action("Details", new { id = product.ProductId })">      

<img alt="@product.Title" src="@product.ProductPicUrl" />      

<span>@product.Title</span> </a>        

</li> 

}

 

 

Jan 21, 2012 at 10:49 PM
Edited Jan 21, 2012 at 10:50 PM

Try this for view : 

 

<div class="variety"> <h3><em>@Model.Name</em> Products</h3>

 <ul id="product-list"> 

@foreach (var product in Model.Products)  

{    

 <li>    

<a href="@Url.Action("Details", new { id = product.ProductId })">      

<img alt="@product.Title" src="../@product.ProductPicUrl" />      

<span>@product.Title</span> </a>        

</li> 

}

Jan 22, 2012 at 12:22 AM
Edited Jan 22, 2012 at 2:09 AM

Thank you, KamranSadin, it worked for the browse page!

However, i am trying to implement the same method for the Details page;

<p>   

<img alt="@Model.Title" src="../@Model.ProductPicUrl" />

</p>

But looks like it doesn't work. (Displays a invalid image thumbnail)

Any workaround for this?

Jan 24, 2012 at 3:42 AM

I added another directory up "../../" and it solved the display problem. Thanks!

Coordinator
Jan 24, 2012 at 7:44 AM
Glad you got it working. The best solution is to use the Url.Content helper ( http://msdn.microsoft.com/en-us/library/system.web.mvc.urlhelper.content.aspx ) as it will automatically generate the correct url's for you, and it handles moves between environments well.

@Url.Content("~/" + product.productPicUrl))

On Monday, January 23, 2012, kaneXtreme wrote:

From: kaneXtreme

I added another directory up "../../" and it solved the display problem. Thanks!

Read the full discussion online.

To add a post to this discussion, reply to this email (mvcmusicstore@discussions.codeplex.com)

To start a new discussion for this project, email mvcmusicstore@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com