Reputation: 5
How this can be "translated" to Orchard
routes.MapRoute(
name: "Durandal App Views",
url: "App/views/{viewName}.cshtml",
defaults: new { controller = "DurandalView", action = "Get" }
);
I tried to make theme based on this.
It is not working and breaks all Orchard site
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())
}
};
}
}`
Upvotes: 0
Views: 1127
Reputation: 741
So it looks like, you are creating your Controller in a Theme.
Why dont you try to build it as a module first.
Going through some tutorials will not harm as Orchard powerful extensibility capabilities take a bit to tune in to.
Orchard Tutorials
Having said that,...
1. Create a Module
2. Add your Routing
3. Create your Get Action
4. Get your View under the Module's Views
folder, probably in a folder called DurandalView
like the controller.
Then you're left with calling the view. Why don't you just try return View(viewName);
You could also have a look at this related question on how to call diferent views SO Question. There, you will be able to see why your ~/App/Views.. will never work. or will not work with the actual folder structure.
Upvotes: 0
Reputation: 71
@ErMasca this was copy-paste error actually code is right - .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())
}
Upvotes: 0
Reputation: 71
Here is controller code as requested
[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 alias module enabled
request to http://localhost
:30321/OrchardLocal/Themes/Durandal/App/views/shell.cshtml gives 404 and no Controller has been invoked
It brakes Orchard at all when priority is set to 100 as exmp
Upvotes: 0
Reputation: 741
Actually, if you look at this
Route = new Route("/App/views/{viewName}.cshmtl", ....
Your View filename is followed by .cshmtl
when it should be .cshtml
Try changing the filetype, that should do it.
Upvotes: 0