简体   繁体   English

MVC5运行时错误

[英]MVC5 runtime error

I am about to lose my mind here because the following makes absolutely no sense whatsoever. 我将在这里失去理智,因为以下内容绝对毫无意义。

Here is my _Layout.cshtml 这是我的_Layout.cshtml

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

Here is my Controller: 这是我的控制器:

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

Here is my View 这是我的看法

@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)
    {

    } 
}

Here is the error 这是错误

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: 编译器错误消息:CS1513:}预期的源错误:

Line 81: } 第81行:}
Line 82: } 第82行:}
Line 83: } 第83行:}

Here is what I tried: 这是我尝试过的:

On my view if I change var adminUser = @Model.IsAdmin; 在我看来,如果我更改var adminUser = @Model.IsAdmin; to var adminUser =true then this works without problems. var adminUser =true则可以正常工作。

If I remove the following code 如果我删除以下代码

if (adminUser)
{

}

then it works without problems. 然后就可以正常工作了。

I don't get it, there are no syntax errors anywhere. 我不明白,任何地方都没有语法错误。 And another thing I don't get is that I emptied out my _Layout.cshtml but yet its failing on line 83, not sure where it is getting those extra html lines from. 我没有得到的另一件事是我清空了_Layout.cshtml,但是在第83行失败了,不确定从哪里获取这些多余的html行。

The problem is that you are writing @Model instead of Model in the if loop. 问题是您在if循环中编写@Model而不是Model Try removing @ and you should be fine. 尝试删除@ ,您应该没问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM