2014-02-14 24 views
2

在我的Footer.cshtml我有一個用於驗證用戶的開關,並檢查模型是否已經提供。if-block裏面的標籤和@model

@model AngemeldeterBenutzerModel 

@if (User.Identity.IsAuthenticated && Model != null) 
{ 
    <span class="span2">Eingelogt als @model.AnzeigeName</span> 
    <span class="offset1 span9">Zuletzt eingelogt mit "@model.LastLoginIp" um "@model.LastLoginDate"</span> 
} 

這一觀點得到在_Layout.cshtml呈現如下:

<div id="footer" class="container-fluid"> 
    @{ Html.RenderAction("Footer", "Navigation"); } 
</div> 

但是我得到這個分析器錯誤:

The if block is missing a closing "}" character. Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup.

但我關上了if - 塊在最後。我還試圖用<text>標籤圍繞內容,或者在兩個跨段之前使用@:

在哪一點違反語法?

+0

我假設模型的屬性實際上不是'.Foo'和'.Bar',你能展示真實的代碼嗎? –

+0

包含現在的真實代碼 –

回答

2

這違反了語法:

@model.AnzeigeName 

您所有的model.property的設置應該是大寫即

@Model.AnzeigeName 

你也可以使用@:輸出,請嘗試以下方法:

@if (User.Identity.IsAuthenticated && Model != null) 
{ 
    @:<span class="span2">Eingelogt als @Model.AnzeigeName</span> 
    @:<span class="offset1 span9">Zuletzt eingelogt mit "@Model.LastLoginIp" um "@Model.LastLoginDate"</span> 
} 
+0

這解決了這個問題,謝謝:) –

+0

沒問題,好運與其餘。 :) – hutchonoid