문제

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.

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top