<#
    var selectedModelProperties = Component["SelectedModelProperties"];
    var autoGenerateFields = Component["AutoGenerateFields"];
    var fields = Component["Fields"];
    var index = 0;
    foreach (var field in fields)
    {
        var hasHeader = !string.IsNullOrEmpty(field["Header"]);
        var fieldName = hasHeader ? field["Header"] : field["Binding"];
        var fieldType = string.Empty;
        var modelExpression = string.Empty;
        foreach (var property in selectedModelProperties)
        {
            if (field["Binding"] == property["Name"])
            {
                fieldType = property["TypeName"];
                break;
            }
        }
        if (!string.IsNullOrEmpty(field["Format"]) && !string.IsNullOrEmpty(fieldType) && fieldType != "string" && fieldType != "bool" && fieldType != "bool?")
        {
            if (fieldType.Contains("?"))
            {
                modelExpression = "Model." + field["Binding"] +".HasValue ? Model." + field["Binding"] +".Value.ToString(\"" + field["Format"] + "\") : \"\"";
            }
            else
            {
                modelExpression = "Model." + field["Binding"] + ".ToString(\"" + field["Format"] + "\")";
            }
            index++;
#>
        @{var property<#= index#> = <#= modelExpression#>;}
<#
        }
        if (hasHeader)
        {
#>
        <dt>
            <#= fieldName#>
        </dt>
<#
        }
        else
        {
#>
        <dt>
            @Html.DisplayNameFor(model => model.<#= fieldName#>)
        </dt>
<#
        }
#>
        <dd>
<#
        if (string.IsNullOrEmpty(modelExpression))
        {
#>
            @Html.DisplayFor(model => model.<#= field["Binding"]#>)
<#
        }
        else
        {
#>
            @Html.DisplayFor(model => property<#= index#>)
<#
        }
#>
        </dd>
<#
    }
#>