我正在尝试一些新的东西(对我来说),为我的布局视图模型使用抽象基类。
问题是,当我按原样运行该网站时,它会抛出一个非常神秘的(对我来说)异常。这个异常是什么意思,我可以采取什么措施来解决它?
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>
布局视图模型
namespace MyApp.Core.ViewModels
{
public abstract class LayoutViewModel
{
public string Title { get; set; }
}
}
索引视图模型
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);
}
和例外
编译错误描述:编译过程中发生错误
服务此请求所需的资源的编译。请
查看以下具体错误详细信息并修改您的源
适当地编码。
编译器错误消息: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
文件\root\b314e0d7\36f522db\App_Web_index.cshtml.a8d08dba.yr7oemfz.0.cs
线路:29