Created
May 9, 2013 11:47
-
-
Save AlexShkor/5547004 to your computer and use it in GitHub Desktop.
HtmlHelper for applying Knockout model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Newtonsoft.Json; | |
namespace System.Web.Mvc | |
{ | |
public static class HtmlHelperExt | |
{ | |
private const string BaseApplyModelScriptString = @"<script type=""text/javascript""> | |
$(function () {{ | |
var model = new AllMessagesModel({0}); | |
ko.applyBindings(model); | |
}}); | |
</script>"; | |
public static IHtmlString ApplyModel(this HtmlHelper page, object model) | |
{ | |
return new MvcHtmlString(string.Format(BaseApplyModelScriptString, JsonConvert.SerializeObject(model))); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment