Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
I am passing json value from view to controller not able to parse in the controller please guide .

Below code for passing Json, not able to get in Curriculum Controller in Create method
JavaScript
<script>

       $(document).ready(function () {
           $("#target").click(function (data, status) {


               var arr = { City: 'Moscow', Age: 25 };
               $.ajax({
                   url: 'http://localhost:61255/Curriculum/Create',
                   type: 'POST',
                   data: JSON.stringify(arr),
                   contentType: 'application/json; charset=utf-8',
                   dataType: 'json',
                   async: false,
                   success: function (msg) {
                       alert(msg);
                   }
               });


           });

       });

   </script>


What I have tried:

Below code to parse the json but not working
[HttpPost]
public ActionResult Create(IDictionary<string,> model)
{
}
Posted
Updated 10-Jun-16 3:26am

1 solution

Your controller action accepts a string dictionary but you're sending a JSON object. The params need to match what you're sending so try

C#
public ActionResult Create(string City, int Age)


Or create a concrete class that has those properties and use that as the controller parameter instead.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900