Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC3 (Razor) Json Get deserialized data in the Controller
    text
    copied!<p>I need help again with Asp.Net MVC (Razor View Engine). In my View (Index) I have</p> <pre><code>@model IEnumerable&lt;Movie&gt; </code></pre> <p>I want to pass the Model to the Controller: I stringify the model in this way:</p> <pre><code>&lt;script type="text/javascript"&gt; function postData(){ var urlact='@Url.Action("createDoc")'; var model ='@Html.Raw(Json.Encode(Model)); $.ajax({ data: JSON.stringify(model), type:"POST", url:urlact, datatype:"json", contentType:"application/json; charset=utf-8" }); } &lt;/script&gt; </code></pre> <p>Everything seems to work, cause I know the stringified data is:</p> <pre><code>'[{"ID":1,"Title":"The Lord of the Rings: The Fellowship of the Ring","ReleaseDate":"\/Date(1007938800000)\/","Genre":"Fantasy","Price":93000000.00},{"ID":2,"Title":"The Lord of the Rings: The Two Towers","ReleaseDate":"\/Date(1039042800000)\/","Genre":"Fantasy","Price":94000000.00},{"ID":3,"Title":"The Lord of the Rings: The Return of the King","ReleaseDate":"\/Date(1070233200000)\/","Genre":"Fantasy","Price":94000000.00}]'; </code></pre> <p>The problem is: in Controller, methodName <em>"createDoc"</em> (as declared in the script) I cannot access to the stringified data. Following some samples founded on the web, my method is something like this:</p> <pre><code>[HttpPost] public ActionResult createDoc(IEnumerable&lt;Movie&gt; movies) { //...using movies list return View(); } </code></pre> <p>Why can't I access to the stringified data? How can I do it, is there some method to call to deserialize the model in the Controller method? Also, can I use the serialize() method instead of the stringify() one? If so, what's the syntax, View &amp; Controller side?</p> <p>Thank you.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload