C# CS1003:语法错误,“>”应在 Razor 中出现
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18877058/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CS1003: Syntax error, '>' expected in Razor
提问by Chase Florell
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
布局视图模型
namespace MyApp.Core.ViewModels
{
public abstract class LayoutViewModel
{
public string Title { get; set; }
}
}
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
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
编译错误说明:在编译服务此请求所需的资源期间发生错误。请查看以下特定错误详细信息并适当修改您的源代码。
编译器错误消息:CS1003:语法错误,应为“>”
源错误:
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
源文件:c:\Users\Chase\AppData\Local\Temp\Temporary ASP.NET Files\root\b314e0d7\36f522db\App_Web_index.cshtml.a8d08dba.yr7oemfz.0.cs 行:29
采纳答案by AakashM
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
其中一个有一个
;
不应该在那里
回答by Marcelo Lujan
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!
这对我行得通!
回答by SEF
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 >
.
编译器一直告诉我它期待一个额外的>
.