ASP.NET MVC Passing model to controller with AJAX

前端 未结 1 460
庸人自扰
庸人自扰 2021-01-22 04:36

I\'m trying to pass a model to my controller with an ajax call.

I\'ve looked at the answer provided by Laviak in the following question but was not able to get it to wor

相关标签:
1条回答
  • 2021-01-22 04:59

    Make sure that the javascript file that is containing the AJAX call is included after the script that defines the MODEL variable in your master file:

    <script type="test/javascript">   
        var MODEL = '<%= Model.ToJson() %>';
    </script>
    <script type="text/javascript" src="<%= Url.Content("~/scripts/myscript.js") %>"></script>
    

    Also I would recommend you taking a look at the following article which illustrates how to pass complex object graphs using JSON AJAX request to a controller.

    0 讨论(0)
提交回复
热议问题