[ACCEPTED]-get value from @Model inside jquery script-model

Accepted answer
Score: 37

@Model is a .NET object (server-side), your 10 JQuery scripts are running client-side and 9 operate on JavaScript objects. You can't 8 directly access server-side .NET objects 7 from client-side code - you'll need to have 6 some JSON serialization of your model (or 5 maybe just the properties you're interested 4 in). Then inside a script you can do something 3 like

var model = @Html.Raw(Json.Encode(Model))

to get your model into a JavaScript 2 variable, then access everything through 1 "model".

More Related questions