2016-01-10 23 views
0

我在這裏會失去理智,因爲以下幾點絕對沒有任何意義。MVC5運行時錯誤

這裏是我的_Layout.cshtml

<!DOCTYPE html> 
<html> 
<head> 
</head> 
<body> 
     @RenderBody() 
</body> 
</html> 

這裏是我的控制器:

[AllowAnonymous] 
public async Task<ActionResult> Show(string id) 
{ 
    var a = new TournamentViewModel(); 
    a.IsAdmin = true; 
    return View(a); 
} 

這是我的看法

@using System.Threading 
@using System.Web.Mvc.Html 
@using Microsoft.AspNet.Identity 
@model MyProj.Models.ViewModels.TournamentViewModel 
@if (@Model != null) 
{ 
    var adminUser = @Model.IsAdmin; 
    if (adminUser) 
    { 

    } 
} 

以下是錯誤

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS1513: } expected Source Error:

Line 81: }
Line 82: }
Line 83: }

這裏是我的嘗試:

在我看來,如果我改變var adminUser = @Model.IsAdmin;var adminUser =true那麼這個工作沒有問題。

如果我刪除下面的代碼

if (adminUser) 
{ 

} 

然後它沒有問題。

我不明白,任何地方都沒有語法錯誤。另一件我不明白的事情是我清空了我的_Layout.cshtml,但它在83行上失敗了,不知道它從哪裏獲得這些額外的html行。

+2

在視圖中,您可以在html塊中使用'@ Model'。從已經啓動的代碼塊中,您只需使用'Model'。你也沒有從你的Show()中返回任何東西。 – GSerg

回答

2

問題是,您正在編寫@Model而不是Model在if循環中。嘗試刪除@,你應該沒問題。