Cha*_*ell 18 c# razor asp.net-mvc-4
我正在为我的布局视图模型使用抽象基类尝试新的东西(对我而言).
问题是,当我按原样运行网站时,它会抛出一个非常神秘的(对我而言)异常.这个例外意味着什么,我可以做些什么来解决它?
布局
@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>
Run Code Online (Sandbox Code Playgroud)
指数
@model MyApp.Core.ViewModels.Home.IndexViewModel;
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h1>@Model.Body</h1>
Run Code Online (Sandbox Code Playgroud)
LayoutViewModel
namespace MyApp.Core.ViewModels
{
public abstract class LayoutViewModel
{
public string Title { get; set; }
}
}
Run Code Online (Sandbox Code Playgroud)
IndexViewModel
namespace MyApp.Core.ViewModels.Home
{
public class IndexViewModel : LayoutViewModel
{
public string Body { get; set; }
}
}
Run Code Online (Sandbox Code Playgroud)
调节器
[HttpGet]
public ActionResult Index()
{
var model = new IndexViewModel
{
Title = "Hello World",
Body = "Hello World"
};
return View(model);
}
Run Code Online (Sandbox Code Playgroud)
和例外
编译错误说明:在编译服务此请求所需的资源期间发生错误.请查看以下特定错误详细信息并相应地修改源代码.
编译器错误消息:CS1003:语法错误,'>'预期
来源错误:
Run Code Online (Sandbox Code Playgroud)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 Line:29
Aak*_*shM 40
比较和对比:
布局
@model MyApp.Core.ViewModels.LayoutViewModel
Run Code Online (Sandbox Code Playgroud)
指数
@model MyApp.Core.ViewModels.Home.IndexViewModel;
Run Code Online (Sandbox Code Playgroud)
知道了吗?这是答案:
其中一个有一个
;不应该在那里