Skip to content

plbonneville/RazorInteractive

Repository files navigation

.NET Interactive Nootbooks Razor Extension

NuGet version (RazorInteractive)

To get started with Razor in .NET Interactive Notebooks, first install the RazorInteractive NuGet package. In a new C# (.NET Interactive) cell enter and run the following:

#r "nuget: RazorInteractive, 1.1.10"

Using the #!razor magic command your code cell will be parsed by a Razor engine and the results displayed using the "txt/html" mime type.

#!razor

@{
    var colors = new [] { "red", "green", "blue" };
}

<ol>
@foreach(var color in colors)
{
    <li style="color: @color;">@color</li>
}
</ol>

The C# and F# kernel variables are all available through the @Model property.

var firstname = "John";
var lastname = "Doe";
var colors = new [] { "red", "green", "blue" };
#!razor

<p>Hello <b>@Model.firstname @Model.lastname</b>, what is you favorite a color?</p>

<ol>
@foreach(var color in Model.colors)
{
    <li style="color: @color;">@color</li>
}
</ol>