I am writing Razor code in a view, and need to call a JavaScript function with the JSON that is rendered by the Razor code:
// JavaScript function
function buildTemplate(currentTemplate) {
alert('hello world');
}
@* Build out entire Template structure in JavaScript *@
@foreach (Template template in Model.Templates)
{
buildTemplate(JsonConvert.SerializeObject(template));
}
For some reason, Razor thinks that buildTemplate is a C# method it can't find, and it errors out.
Has anyone done this before? Any advice?
Thanks,
Philip