Skip to main content

Posts

Showing posts with the label Durandal

Durandal.js: Enable Razor views

By default when you use the Durandal MVC template , your views should be created as plain html files. But what if you want to use ASP.NET MVC Razor files(.cshtml) instead? This is perfectly possible but requires some configuration work from you: First, let’s switch the Durandal view extension from .html(the default) to .cshtml. Open up the main.js file and set the viewExtension property on the viewEngine object: The next step is to create a generic controller that will serve .cshtml files: And of course, don’t forget to add a route that matches this controller: As a last step copy the web.config file from Views/web.config to /App/views/web.config (so Razor views work in this location):

Durandal: jQuery and Knockout integration

Durandal is a really great SPA framework. But we had some trouble first to get it up and running. The problem was that we forgot 2 very important lines inside our Durandal main.js: It’s important to define both Knockout and jQuery as RequireJs modules. Without that Durandal remained silent…