Click here to Skip to main content
15,888,908 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hey every one i want to ask how to get the values from mvc model in jquery..

here is my code
C#
<pre lang="xml"><script type="text/javascript">
        $(document).ready(function () {

C#
for (var j = 0; j < '@Model.Count' / 2; j++)
               {
                   getHalfViewPage('@(Html.Raw(Url.Action("LoadReports", "Dashboard", new { @area = "Home", showfullWidth = true, DMFormDefKey = Model.ElementAt(0).deffromkey }, Request.Url.Scheme)))', "halfViewList1-" + j);
               }

</script>

this is "Model.ElementAt(0).deffromkey" always pass "zero 0". how to get the orignal value. please help me..
Posted

1 solution

JavaScript
<script type="text/javascript">
   
 var yourModel =    '@Html.Raw(Json.Encode(Model))';

// yourModel now contains your MVC (server side) model as json serialized model.
alert(yourModel.whatEverPropertyYouWant);

</script>
 
Share this answer
 
v3
Comments
F-ES Sitecore 11-Mar-15 5:30am    
// no apostrophes and one less close parenthesis
var yourModel = @Html.Raw(Json.Encode(Model));

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