Your C# objects into Javascript

Keywords: Json, Json Parse, Json Encode, javascript, C#
Publish Date: 12/30/2012
Description: Encode and Parse information from your model into javascript in a Razor view

This is very useful. In this example I'm giving jquery UI auto complete a list of strings for my blog search.

Update: I switched to newton soft for Json because it does dates in a better format.

$(function () {
        var quickSearches = JSON.parse('@Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(Model.QuickSearches))');
        var blogTypeGuid = '@Html.Raw(Model.BlogTypeGuid)';
        Ch.BlogIndex.wireBlogIndex(quickSearches, blogTypeGuid);

Comments (0):

Leave a Comment:

    Captcha Challenge