Skip to main content
100%

Json Model Binding with Knockout and ASP.NET MVC

✓ Published0🌍 Public
MMcNull
Last edited Nov 27, 2012
Created on Nov 27, 2012

This example shows how Knockout.js binds a customer form in an ASP.NET MVC view to a client-side view model, using a custom `JsonModelBinder` to deserialize submitted JSON into a `CustomerViewModel` server-side. The `Edit.cshtml` view uses `ko.applyBindings` to connect `ko.observable` properties like `Name` and `Id` to HTML inputs via `data_bind` attributes, while `toJson` in `HtmlHelperExtensions` serializes the server model for initial client data. The `viewModels.js` file defines a `Save` method that posts JSON to the controller’s `[HttpPost] Edit` action using `ko.utils.postJson`, with jQuery unobtrusive validation wired through `$.validator.unobtrusive.parse` and a custom `submitHandler`.

AI-generated description

Similar vizzes