jquery - Always getting null values in controller for ajax post -


i tried ajax post view shown below (using jquery).

complete solution here.

 $(document).ready(function () {                 var kk = {                     address1: "423 judy road",                     address2: "1001",                     city: "new york",                     state: "ny",                     zipcode: "10301",                     country: "usa"                 };                 console.log(json.stringify(kk));                 $.ajax({                     url: 'check',                     type: 'post',                     data: json.stringify(kk),                     datatype:"json",                     contenttype: 'application/json; charset=utf-8',                     success: function (data) {                         alert(data.success);                     },                     error: function () {                         alert("error");                     }                 });             }); 

and received in controller (the method invoked)

public actionresult check(addressinfo addressinfo)         {             return json(new { success = true });         }  

model here, when tried access (break point checked) properties of object (addressinfo) showed null value. tried without stringifying , stringifying. 'm learning mvc , beginner. please help

the reason isn't working because you're using asp.net mvc 2 , support model binding json wasn't added until asp.net mvc 3.

you can add functionality asp.net mvc 2 though. phil haack has post describing that, link sample code @ end: http://haacked.com/archive/2010/04/15/sending-json-to-an-asp-net-mvc-action-method-argument.aspx


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -