How can I make sitecore display an image (or other resources)

I installed pure Sitecore 6.6 and enabled MVC support using this tutorial . So my environment is Sitecore 6.6, ASP.NET MVC 3 and Razor, Microsoft SQL Server Express 2012, IIS 7.5, and I'm using Microsoft Visual Studio 2012 Express for the web. I have the following code:

@Model.PageItem.Fields["Title"];<br />
@Model.PageItem.Fields["Image"].GetValue(true, true);<br />
@Model.PageItem.Fields["Text"];<br />
Sitecore.Data.Items.MediaItem item = Model.PageItem.Fields["Image"].Item;
@Sitecore.StringUtil.EnsurePrefix('/', Sitecore.Resources.Media.MediaManager.GetMediaUrl(item));<br />

      

The result is simple:

Sitecore
<image mediaid="{4DFD3ABC-0BC0-41D2-BD38-705946A1368A}" mediapath="/Images/xbox" src="~/media/4DFD3ABC0BC041D2BD38705946A1368A.ashx" />
<p>Welcome to Sitecore</p> 
/sitecore/shell/~/media/110D559FDEA542EA9C1C8A5DF7E70EF9.ashx

      

When I go to the path given on the last line, I get the following error:

HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

      

I have tried several things, for example:

  • Media.UseItemPaths in Web.config changed to trye (or false) - nothing works ...
  • Media.RequestExtension in Web.config set to empty (ashx by default)
  • I added ashx for allowed extensions in Web.config (because if I don't have normal extensions I at least want to have a working ashx link)
  • I added ashx to IIS 7.5 -> Request Filtering -> Filename Extensions

Of course, after every change (just in case) I restarted the server and cleared the browser cache (in fact, after a few requests, I had my cache disabled for chrome).

I searched for a solution on sdn.sitecore.net with no luck. I actually spent over 3 hours looking for a solution and can't figure out what is going wrong ... Any help or suggestions are appreciated!

+2


source to share


1 answer


The Field method of the Sitecore.Mvc.Helpers.SitecoreHelper class will allow you to display an image field.

Here's a View Rendering example that outputs your three fields:



@using Sitecore.Mvc.Presentation
@using Sitecore.Mvc
@model RenderingModel

@Html.Sitecore().Field("Title")<br />
@Html.Sitecore().Field("Image")<br />
@Html.Sitecore().Field("Text")<br />

      

John West blog widely on Sitecore MVC, you may like his About MVC Helpers with Sitecore ASP.NET CMS post.

+6


source







All Articles