Knockoutjs - how can you pass the model to the view?

$. Ajax({ url: 'Home/GetUserData', type: 'post', success: function (data) { viewModel = ko.mapping. FromJS(data); viewModel.

Save = function () { sendToServer(); }; ko. ApplyBindings(viewModel); } }) You will also need to use the mapping plugin knockoutjs.com/documentation/plugins-map... Notice the ko.mapping. FromJS(data); which is taking the model from the mvc endpoint and prepping it for observable.

$. Ajax({ url: 'Home/GetUserData', type: 'post', success: function (data) { viewModel = ko.mapping. FromJS(data); viewModel.

Save = function () { sendToServer(); }; ko. ApplyBindings(viewModel); } }); You will also need to use the mapping plugin. knockoutjs.com/documentation/plugins-map... Notice the ko.mapping.

FromJS(data); which is taking the model from the mvc endpoint and prepping it for observable.

– Simon G Apr 21 at 10:27 Yes works a treat. – RubbleFord Apr 21 at 12:35.

I am not using the ko. Mapping plugin. I think the mapping plugin works two-way (which is not your case).

I have declared an Html Helper > public static string ToJson(this object obj) { var serializer = new JavaScriptSerializer(); return serializer. Serialize(obj); } which serializes my server-side module to the client size JSON and declare it at the client end.

The accepted answer uses JQuery. This works perfectly well but isn't required. See: blog.stevensanderson.com/2010/07/12/edit....

You will also need to use the mapping plugin.

Here's an article that helped me: http://www.codeproject.com/Articles/332406/Client-side-Model-binding-with-ASP-NET-MVC-3-and-K.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions