正在尝试设置移动频道以在EPiServer 7的编辑模式下使用。
我一直在关注这个链接
http://world.episerver.com/Documentation/Items/Developers-Guide/EPiServer-CMS/7/Content/Display-Channels/
创建了一个初始化模块
[InitializableModule]
[ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
public class DisplayModesInitialization : IInitializableModule
{
public void Initialize(InitializationEngine context)
{
if (context.HostType == HostType.WebApplication)
{
System.Web.WebPages.DisplayModeProvider.Instance.Modes.RemoveAt(0);
context.Locate.DisplayChannelService()
.RegisterDisplayMode(new DefaultDisplayMode(RenderingTags.Mobile)
{
ContextCondition = (r) => r.Request.Browser.IsMobileDevice
});
}
}
public void Preload(string[] parameters) { }
public void Uninitialize(EPiServer.Framework.Initialization.InitializationEngine context) { }
}正如您所看到的,我尝试删除现有的“移动”显示模式,以替换为通过EPiServer DisplayChannelService()创建的显示模式。
只需浏览主页就可以了,但当我强制userAgent成为移动浏览器时,它确实会命中正确的视图……即Index.mobile.cshtml
然而,它似乎仍然在寻找_Layout.cshtml,而不是_Layout.mobile.cshtml,即使是这样,它也无法找到它。
The file "~/Views/Shared/_Layout.cshtml" could not be rendered, because it does not exist or is not a valid page.有没有人成功地通过EPiServer DisplayChannelService为MVC创建了一个移动IDisplayMode?
另外,如果我在移动视图中显式设置布局
@{
Layout = "~/Views/Shared/_Layout.mobile.cshtml";
}如果也找不到呢?
The file "~/Views/Shared/_Layout.mobile.cshtml" could not be rendered, because it does not exist or is not a valid page._Layout和_Layout.mobile是否都存在于该位置?
发布于 2013-05-25 02:55:58
设法让它工作起来了。
发现_ViewStart.cshtml具有以下设置:
@{
Layout = "~/Views/Shared/_Layout.cshtml";
DisplayModeProvider.Instance.RequireConsistentDisplayMode = true;
} 因此,我删除了DisplayModeProvider.Instance.RequireConsistentDisplayMode = true;,它现在可以工作了。
不确定为什么这会导致问题,因为主页有移动和桌面视图,也有移动和桌面布局?
https://stackoverflow.com/questions/16730568
复制相似问题