Asp.Net MVC(Razor View Engine)についてもう一度サポートが必要です。私のビュー(インデックス)には
@model IEnumerable<Movie>
モデルをコントローラーに渡したい:モデルを次のように文字列化します。
<script type="text/javascript">
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"
});
}
</script>
すべてが機能しているようです。文字列化されたデータは次のとおりです。
'[{"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}]';
問題は次のとおりです。Controllerでは、methodName "createDoc"(スクリプトで宣言されている)で、文字列化されたデータにアクセスできません。Webで作成されたいくつかのサンプルに続いて、私の方法は次のようになります。
[HttpPost]
public ActionResult createDoc(IEnumerable<Movie> movies)
{
//...using movies list
return View();
}
文字列化されたデータにアクセスできないのはなぜですか?どうすればそれを行うことができますか、Controllerメソッドでモデルを逆シリアル化するために呼び出すメソッドはありますか?また、stringify()メソッドの代わりにserialize()メソッドを使用できますか?もしそうなら、構文、ビュー&コントローラー側は何ですか?
ありがとうございました。