powershellrazorrazorenginerazorgenerator

Powershell and Razor Template


I'm using PowerShell and Render-RazorTemplate.ps1 to create a html page

I have a 'System.Collections.Hashtable' passing to my Model and i'm not getting this to work

@foreach (var s in Model)
{
    <div class="BTC-setting"><i class='fa @(s["Icon"])'></i><span>@s["Name"]</span></div>
}

If I use like this

class='fa @(s["Icon"])'

I have an error like

The name 'WriteAttribute' doesn't exist on the actual context
>>> WriteAttribute("class", Tuple.Create(" class=\'", 225), Tuple.Create("\'", 248)**

If I remove the @(s["Icon"]) from inside of the property class it works and shows me the value

Someone have any ideas about this?


Solution

  • Just found the solution to my issue, just put @: at the begging of the html tags that uses variables inside quotes

    ISSUE

    @foreach (var s in Model)
    {
        <div class="BTC-setting"><i class='fa @(s["Icon"])'></i><span>@s["Name"]</span></div>
    }
    

    SOLUTION

    @foreach (var s in Model)
    {
        @:<div class="BTC-setting"><i class='fa @(s["Icon"])'></i><span>@s["Name"]</span></div>
    }