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);