<#
var selectedModelProperties = Options["SelectedModelProperties"];
var autoGenerateFields = Options["AutoGenerateFields"];
var fields = Options["Fields"];
var index = 0;
foreach (var field in fields)
{
    var fieldName = 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 #>;}
<#
    }
#>
        <dt>
            <#= fieldName #>
        </dt>
        <dd>
<#
    if (string.IsNullOrEmpty(modelExpression))
    {
#>
            @Model.<#= field["Binding"] #>
<#
    }
    else
    {
#>
            @property<#= index #>
<#
    }
#>
        </dd>
<#
}
#>