json - JsonValueProvider not working in ASP.NET MVC3 -


I'm having trouble compelling a view modal for json in MVC3, my very simple code is down ...

  & lt; Asp: Content ID = "Content2" content placeholder ID = "MainContent" runat = "server" & gt; Using the & lt;% (Html.BeginForm ("Save", "Home")) {%> & Lt; P & gt; Cat & lt; / P & gt; & Lt; Button id = "clickMe" type = "submit" & gt; Click me & lt; / Button & gt; & Lt;%}% & gt; & Lt; Script type = "text / javascript" & gt; $ (Function () {$ ('form'). Submit (function () {var cat = {age: 5, weight: 13.5, name: 'phulfi'}; $ .ajax ({url: '/ home / Save ', type:' post ', data: JSON.stringify (cat), datatype:' Jason ', content type:' application / jason; charset = UTF-8 '}); console.info (JSON.stringify cat)) ;});}); & Lt; / Script & gt; & Lt; / ASP: Content & gt;   

The console.info line is printed in the FireBug Information window so that the script is closing at the right time. Expected JSON also appears in firebug ...

  source {"age": 5, "weight": 13.5, "name": "fluffy"}   

However, when the visual model comes in the action method below all methods, then it is uninstalled ...

  public class cat {public ent era {receive; Set; } Public Double Weight {Receive; Set; } Public string name {get; Set; }} [Http post] Public Action Result Service (CAT form) {Return View (); }   

I have verified that the app is registered in the JasonVoluProvirFactory factories. I am convinced that I am missing something incredibly simple, can anyone put any light on it is?

Thanks in advance.

This should work, do not forget to return false and cancel the default form:

  $ ('form'). Submit (function () {var cat = {age: 5, weight: 13.5, name: 'alcoholic'}; $ .ajax ({url: this.href, type: this.method, data: JSON.stringify (cat ), Datatype: 'Jason', Content Type: 'Application / Jason; Charset = UTF-8'}); Return False;}); In addition, you have specified the  datatype: 'Jason' , so make sure your administrator returns the action to JSON:  
 [Code> [HttpPost] Save public battle result (cat form) {back Jason (new {message = "success"}); }    

Comments

Popular posts from this blog

qt - switch/case statement in C++ with a QString type -

python - sqlite3.OperationalError: near "REFERENCES": syntax error - foreign key creating -

Python's equivalent for Ruby's define_method? -