CS1003:语法错误,“>"预期在剃刀 [英] 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?
布局
@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>
索引
@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; }
}
}
控制器
[HttpGet]
public ActionResult Index()
{
var model = new IndexViewModel
{
Title = "Hello World",
Body = "Hello World"
};
return View(model);
}
和例外
编译错误说明:在执行过程中发生错误 满足该请求所需的资源的汇编.请 查看以下特定的错误详细信息并修改您的源 适当地编码.
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.
编译器错误消息:CS1003:语法错误,预期为'>'
Compiler Error Message: CS1003: Syntax error, '>' expected
源错误:
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 文件\ root \ b314e0d7 \ 36f522db \ App_Web_index.cshtml.a8d08dba.yr7oemfz.0.cs 行:29
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
推荐答案
比较和对比:
布局
@model MyApp.Core.ViewModels.LayoutViewModel
索引
@model MyApp.Core.ViewModels.Home.IndexViewModel;
知道了吗?答案是这样:
Got it yet? Here's the answer:
其中一个有一个
;
不应该在那里
这篇关于CS1003:语法错误,“>"预期在剃刀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!