2013-02-08 41 views
2

我安装了干净的Sitecore 6.6并启用了使用此guide的MVC支持。所以我的环境是Sitecore 6.6,ASP .NET MVC 3和Razor,Microsoft SQL Server Express 2012,IIS 7.5以及我正在使用Microsoft Visual Studio 2012 Express for Web。我有以下代码:我如何让sitecore显示图像(或其他资源)

@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 /> 

结果很简单:

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 

当我浏览到最后一行指定的路径我得到以下错误:

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

我试过几件事情,例如:

  1. Web.config中的Media.UseItemPaths改为trye(或虚假) - 没有什么工作......在Web.config中设置为空
  2. Media.RequestExtension(ashx的是默认值)
  3. 我已经加入到的ashx允许在Web.config文件扩展名(因为如果我不能有正常的扩展,我至少希望有工作的ashx链接)
  4. 我已经加入ASHX到IIS 7.5 - >请求过滤 - >文件扩展名

当然,每次更改后(以防万一)我重新启动服务器并清除浏览器的缓存(实际上,在几次请求之后,我已禁用了Chrome的缓存)。

我正在寻找sdn.sitecore.net上的解决方案,但没有运气。其实我已经花了3个多小时寻找解决方案,并且无法弄清楚发生了什么问题......任何帮助或建议都会被赞赏!

回答

6

Sitecore.Mvc.Helpers.SitecoreHelper类的Field方法将允许您输出Image字段。

下面是一个例子查看渲染输出的三个字段:

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

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

约翰·韦斯特在Sitecore的MVC广泛热议,你可能想看看他About MVC Helpers with the Sitecore ASP.NET CMS岗位。

+0

@ Html.Sitecore()。Field(“Image”)完成了这项工作!非常感谢凯文 - 我不知道为什么你的代表点比我低...... – Karol

+0

没问题,很高兴你有它的工作。 –

相关问题