While working on a view in which I am writing Razor code, I encountered the need to call a JavaScript function with the JSON generated 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));
}
However, Razor seems to be confusing buildTemplate
as a C# method that it cannot locate, resulting in an error.
Has anyone faced a similar issue before? Any suggestions or advice would be greatly appreciated.
Thank you,
Philip