Mithril in Razor Pages

artydev - Apr 29 '20 - - Dev Community

Sometimes I fill easier to use Mithril for rendering list in Razor pages.
Notice how Mithril gets the target element width id list. We simply put the term list without even quoting it, awesome.

@{
    string[] data = new string[] { "Raph", "Mila", "Cath", "Marcel" };
}

<div id="list"></div>

<script>
    const  data = @Html.Raw(Json.Serialize(data));
    m.render(list, m("ul", data.map(name => m("li", `Hello ${name}`))))
</script>

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .