Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
@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 -->
var DynamicModelLoading = function(data) {
var self = this;
ko.mapping.fromJS(data, {}, self);
self.displayFullName = function(model) {
var fullName = model.firstName() + " " + model.lastName();
alert(fullName);
};
};
@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