简体   繁体   English

CS1003:Razor中预期的语法错误,'>'

[英]CS1003: Syntax error, '>' expected in Razor

I'm trying something new (to me) in using an abstract base class for my layout viewmodel. 我正在为我的布局视图模型使用抽象基类尝试新的东西(对我而言)。

The problem is that when I run the site as is, it throws a very cryptic (to me) exception. 问题是,当我按原样运行网站时,它会抛出一个非常神秘的(对我而言)异常。 What does this exception mean, and what might I do to resolve it? 这个例外意味着什么,我可以做些什么来解决它?

Layout 布局

@model MyApp.Core.ViewModels.LayoutViewModel

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>@Model.Title</title>
</head>
<body>
    <div>
       @RenderBody()
    </div>
</body>
</html>

Index 指数

@model MyApp.Core.ViewModels.Home.IndexViewModel;

@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}


<h1>@Model.Body</h1>

LayoutViewModel LayoutViewModel

namespace MyApp.Core.ViewModels
{
    public abstract class LayoutViewModel
    {
        public string Title { get; set; }
    }
}

IndexViewModel IndexViewModel

namespace MyApp.Core.ViewModels.Home
{
    public class IndexViewModel : LayoutViewModel
    {
        public string Body { get; set; }
    }
}

Controller 调节器

[HttpGet]
public ActionResult Index()
{
    var model = new IndexViewModel
        {
            Title = "Hello World",
            Body = "Hello World"
        };


    return View(model);
}

And the Exception 和例外

Compilation 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: CS1003: Syntax error, '>' expected 编译器错误消息:CS1003:语法错误,'>'预期

Source Error: 来源错误:

 Line 27: Line 28: Line 29: public class _Page_Views_Home_Index_cshtml : System.Web.Mvc.WebViewPage<FutureStateMobile.Core.ViewModels.Home.IndexViewModel;> { Line 30: Line 31: #line hidden 

Source File: c:\\Users\\Chase\\AppData\\Local\\Temp\\Temporary ASP.NET Files\\root\\b314e0d7\\36f522db\\App_Web_index.cshtml.a8d08dba.yr7oemfz.0.cs Line: 29 源文件:c:\\ Users \\ Chase \\ AppData \\ Local \\ Temp \\ Temporary ASP.NET Files \\ root \\ b314e0d7 \\ 36f522db \\ App_Web_index.cshtml.a8d08dba.yr7oemfz.0.cs Line:29

Compare and contrast: 比较和对比:

Layout 布局

@model MyApp.Core.ViewModels.LayoutViewModel

Index 指数

@model MyApp.Core.ViewModels.Home.IndexViewModel;

Got it yet? 知道了吗? Here's the answer: 这是答案:

one of them has a ; 其中一个有一个; which shouldn't be there 哪个不应该在那里

I just add the line twice, and deleted... problem solved! 我只是添加两行,并删除...问题解决了!

@model MyApp.Core.ViewModels.LayoutViewModel
@model MyApp.Core.ViewModels.Layout_OrOther_Model

Try to compile, you get an error (only one model blah, blah..) Delete one of them. 尝试编译,你得到一个错误(只有一个模型等等,等等......)删除其中一个。

@model MyApp.Core.ViewModels.LayoutViewModel

Compile. 编译。

That works for me! 这对我行得通!

bad: 坏:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<DSNY.Core.Interfaces.IUser>" %>

versus

good: 好:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<DSNY.Core.Interfaces.IUser>>" %>

Compiler kept telling me it was expecting an extra > . 编译器一直告诉我它期待额外的>

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

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