Question

I have a asp.net Hot Towel SPA application and I want to use both .html and .cshtml pages.

Is it possible to add multiple viewExtensions:

viewEngine.viewExtension = '.cshtml';
viewEngine.viewExtension = '.html';
Was it helpful?

Solution

viewExtension is not an array, so at the outset, you cannot set multiple viewExtensions. Of course, this is just javascript and you could go into the source and change viewEngine.js from the core Durandal app folder(the link is here: https://github.com/BlueSpire/Durandal/blob/master/App/durandal/viewEngine.js).

That being said, if the client pulls down a *.cshtml file the razor syntax will not be rendered in the way that you believe that it will be. If the server serves up the *.cshtml view then it will be rendered before being spit out to the client. Your best bet, if you are looking for dynamic view rendering with Durandal is to override one or both functions in the viewEngine, being: viewEngine.convertViewIdToRequirePath(viewId):string and for even further control viewEngine.createView(viewId):promise.

For more info, check this link: Routing and Leveraging Dynamic Content in DurandalJS

OTHER TIPS

Take a look at this Gist: https://gist.github.com/irium/5191764

It's my own solution for similar problem. These are customizations for Durandal's viewEngine and viewLocator. Import this module in your shell module and run both customizeViewEngine() and customizeViewLocator() functions. After that views with .html extension will be processed as before, but .cshtml views will be requested from remote server. But remember: due to view caching of Durandal this will only be done once. All subsequent requests of the same view will use cached version at the client side. This can be changed by manually deregister the view's module from RequireJS, but this is out of scope of my needs

This is CoffeScript code compiled to JavaScript, but I hope you'll get the idea and my code will help you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top