Question

i'm working with knockoutjs and MVC and i really don't know how to pass data from Knockoutjs to Controller. I try to use

    self.NextButton = function () {
        $.post("/User/MyAction', self.uUserSet);
    }

but not work. Please show me how to do this. Thanks.

Was it helpful?

Solution

There are several ways to get data back to an MVC controller from Knockout.

A good post demonstrating this is MVC jQuery submit form (without page refresh) from JavaScript function.

Steve Sanderson did a presentation at TechDays in the Netherlands in February where he demonstrated passing data from Knockout to MVC (or actually to the new WebAPI) using the renamed RIA/JS library (now Upshot.js). Upshot does have some challenges but it provides a good solution. It is well worth investigating.

http://channel9.msdn.com/Events/TechDays/Techdays-2012-the-Netherlands/2159

[Here is a question and answer I posted regarding some of the challenges of using Upshot. https://stackoverflow.com/questions/10711637/what-would-make-entity-framework-upshot-believe-my-object-graph-contains-cycl] You can also find information (and examples) on the main Knockout website (http://knockoutjs.com/), and on Ryan Niemeyer's blog (http://www.knockmeout.net/).

You may also want to take a look JSON.NET. http://james.newtonking.com/projects/json-net.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top