Skip to content

Instantly share code, notes, and snippets.

[Route("api/user/{id}")]
public virtual HttpResponseMessage Post(User user)
{
if (!ModelState.IsValid)
{
return Request.CreateResponse(HttpStatusCode.BadRequest);
}
Session.SaveOrUpdate(user);
requirejs.config({
paths: {
'text': '../Scripts/text',
'durandal': '../Scripts/durandal',
'plugins': '../Scripts/durandal/plugins',
'transitions': '../Scripts/durandal/transitions'
}
});
define('jquery', function() { return jQuery; });
public class DurandalViewController : Controller
{
//
// GET: /App/views/{viewName}.cshtml
[HttpGet]
public ActionResult Get(string viewName)
{
return View("~/App/views/" + viewName + ".cshtml");
}
}
routes.MapRoute(
name: "Durandal App Views",
url: "App/views/{viewName}.cshtml",
defaults: new { controller = "DurandalView", action = "Get" }
);
var name = ko.observable('Bert');
var upperCaseName = ko.computed(function() {
return name().toUpperCase();
});
function AppViewModel() {
var self = this;
self.firstName = ko.observable('Bob');
self.lastName = ko.observable('Smith');
self.hasChanges = ko.computed(function() {
ko.toJSON(self);
console.log("changed");
var name = ko.observable('Bart').extend({ rateLimit: 500 });
//Name will only change to uppercase after 0.5 seconds
var upperCaseName = ko.computed(function() {
return name().toUpperCase();
});
<handlers>
<add name="HtmlFileHandler" path="*.html" verb="GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0"/>
</handlers>
routes.MapRoute(
name: "Durandal App Views",
url: "App/features/{viewName}.html",
defaults: new { controller = "DurandalView", action = "Get" }
);
function locationHashChanged() {
//if Google Analytics is available, then push the current location
if (_gaq !== undefined) {
_gaq.push(['_trackPageview', path]);
}
}
window.onhashchange = locationHashChanged;