Last active
December 24, 2015 01:59
-
-
Save jasonmitchell/6727372 to your computer and use it in GitHub Desktop.
Full sample project: https://github.com/jasonmitchell/aspnetmvc-knockoutjs-quickstart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@using Quickstart.Web.Extensions | |
@model Quickstart.Web.Models.Person | |
@section scripts | |
{ | |
<script type="text/javascript"> | |
var viewModel = ko.mapping.fromJS(@Html.Raw(Model.ToJson())); | |
ko.applyBindings(viewModel); | |
</script> | |
} | |
<!-- HTML for view - knockout bindings etc --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var DynamicModelLoading = function(data) { | |
var self = this; | |
ko.mapping.fromJS(data, {}, self); | |
self.displayFullName = function(model) { | |
var fullName = model.firstName() + " " + model.lastName(); | |
alert(fullName); | |
}; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@using Quickstart.Web.Extensions | |
@model Quickstart.Web.Models.Person | |
@section scripts | |
{ | |
<script type="text/javascript" src="/Scripts/ViewModels/DynamicModelLoading.js"></script> | |
<script type="text/javascript"> | |
var viewModel = new DynamicModelLoading(@Html.Raw(Model.ToJson())); | |
ko.applyBindings(viewModel); | |
</script> | |
} | |
<!-- HTML for view - knockout bindings etc --> | |
<a href="#" data-bind="click:displayFullName">Display full name</a> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment