asp.net mvc 4 - error on Converting json data to model at controller -


In ASP.NET MVC4, I have to post a JSN data in the controller and change JSON back to the model to use the AJAX method. I am able to get Jasonson from my model, but I can not change it back I found an exception in my controller. Here I make a model object which is called as Jason Type by another AJAX method. Public class LiveController: Controller {// // GET: / Live / public JsonResult myproduct {Product booklet = new product {pId = 1, pName = "novel"}; Jason Returns (Book, Jansenview Behavior, Elou Gate); } Public Activity View Product () {Return View (); } [Hpp post] Public string loadproduct (string book 1) {product value = jscon convert. Directoryal Object & lt; Product & gt; (Book 1); Return "ready"; }} Public class product {public string pName {get; Set; } Public int pId {get; Set; }} $ (Document) .ready (function () {var book; $ ('# searchbtn'). Click (function () {$ .ajax ({url: "/ live / myproduct", type: "GET" "Jason", Content Type: "Application / Jason", Data: {}, Success: Function (Results) ('(+ + Val +' & lt; / li & gt; ");});}});}); $ ('# postbtn'). Click (function () {var Book1 = JSON.stringify (Book); $ .jax ({url: "/ live / loadproduct", type: "post", cache: incorrect, async: true, data type: "json", contentType: "application / json", data: book 1, success: function (w Warning ("success");}, error: function (xhr, ajaxOptions, thrownError) {warning (xhr.status);}}}}}};});

Please provide a solution.

do this:

  var Jsonobject = JsonConvert.DeserializeObject & lt; Products & gt; ("jsonstring"); // Pass your String JSON here Product Results = Jsonobject.Product;    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -