我有以下代码:
public string View(string view, object model)
{
var template = File.ReadAllText(HttpContext.Current.Request.MapPath(@"~\Views\PublishTemplates\" + view + ".cshtml"));
if (model == null)
{
model = new object();
}
return RazorEngine.Razor.Parse(template, model);
}
我正在使用以下视图
@model NewsReleaseCreator.Models.NewsRelease
@{
Layout = "~/Views/Shared/_LayoutBlank.cshtml";
}
@Model.Headline
我正进入(状态:
[NullReferenceException:对象引用未设置为对象的实例。] c:\Users\Matthew\Documents\GitHub\RazorEngine\src\Core\ 中的 RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context) RazorEngine.Core\Templating\TemplateBase.cs:139
如果我删除布局线它工作正常
我的布局
<!DOCTYPE html>
<html>
<head>
@RenderSection("MetaSection", false)
<title>@ViewBag.Title</title>
@RenderSection("HeaderSection", false)
</head>
<body>
@RenderBody()
</body>
</html>
想法?