如何将其“翻译”到Orchard
routes.MapRoute(
name: "Durandal App Views",
url: "App/views/{viewName}.cshtml",
defaults: new { controller = "DurandalView", action = "Get" }
);
我尝试根据this制作主题。
它不起作用并打破了所有Orchard网站
public class Routes : IRouteProvider {
public void GetRoutes(ICollection<RouteDescriptor> routes) {
foreach (var routeDescriptor in GetRoutes())
routes.Add(routeDescriptor);
}
public IEnumerable<RouteDescriptor> GetRoutes()
{
return new[] {
new RouteDescriptor {
Priority = 5,
Route = new Route(
"/App/views/{viewName}.cshmtl",
new RouteValueDictionary {
{"area", "Durandal"},
{"controller", "DurandalView"},
{"action", "Get"}
},
new RouteValueDictionary(),
new RouteValueDictionary {
{"area", "Durandal"}
},
new MvcRouteHandler())
}
};
}
}`
答案 0 :(得分:0)
实际上,如果你看一下这个
Route = new Route("/App/views/{viewName}.cshmtl", ....
您的视图文件名后面是.cshmtl
,应该是.cshtml
尝试更改应该执行此操作的文件类型。
答案 1 :(得分:0)
这是控制器代码按要求
[Themed]
public class DurandalViewController : Controller
{
private readonly IContentManager _contentManager;
private readonly IWorkContextAccessor _workContextAccessor;
public DurandalViewController(IContentManager contentManager, IWorkContextAccessor workContextAccessor, IShapeFactory shapeFactory, IOrchardServices services)
{
_contentManager = contentManager;
_workContextAccessor = workContextAccessor;
Shape = shapeFactory;
Services = services;
T = NullLocalizer.Instance;
}
dynamic Shape { get; set; }
public IOrchardServices Services { get; private set; }
public Localizer T { get; set; }
[HttpGet]
public ActionResult Get(string viewName)
{
return View("~/App/views/" + viewName + ".cshtml");
}
//public ActionResult Display(int id)
//{
// var contentItem = _contentManager.Get(id, VersionOptions.Published);
// dynamic model = _contentManager.BuildDisplay(contentItem);
// var ctx = _workContextAccessor.GetContext();
// ctx.Layout.Metadata.Alternates.Add("Layout_Null");
// return new ShapeResult(this, model);
//}
}
启用了Orchard别名模块
请求http:// localhost
:30321 / OrchardLocal / Themes / Durandal / App / views / shell.cshtml给出404并且没有调用Controller
当优先级设置为100作为exmp
时,它会对Orchard进行制动答案 2 :(得分:0)
@ErMasca 这是复制粘贴错误 实际上代码是对的 - .cshtml
new RouteDescriptor {
Priority = -15,
Route = new Route(
"/App/views/{viewName}.cshtml",
new RouteValueDictionary {
{"area", "Durandal"},
{"controller", "DurandalView"},
{"action", "Get"}
},
new RouteValueDictionary(),
new RouteValueDictionary {
{"area", "Durandal"}
},
new MvcRouteHandler())
}
答案 3 :(得分:0)
所以看起来,你是在主题中创建你的控制器。
为什么不尝试首先将其构建为模块。
通过一些教程不会有害,因为Orchard强大的可扩展性功能需要一点点调整。
Orchard Tutorials
话虽如此,......
1.创建模块
2.添加您的路由
3.创建您的获取行动
4.在模块的Views
文件夹下获取您的视图,可能在控制器中名为DurandalView
的文件夹中。
然后你离开了调用视图。为什么不试试return View(viewName);
你还可以查看有关如何调用不同观点SO Question的相关问题。在那里,你将能够看到为什么你的〜/ App / Views ..永远不会工作。或不适用于实际的文件夹结构。