Converting C# objects to a javascript object in ASP.NET MVC Razor.

There are times, when you need to pass a C# object as is to your JavaScript code, this is something that I do a lot of time and still keep forgetting.

Finally putting it down here.

<script type="text/javascript">
var projectJson = '@(Html.Raw(new JavaScriptSerializer().Serialize(Model)))';
window.project = JSON.parse(projectJson);
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.