I have the following code:
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); }
and I use the following form
@model NewsReleaseCreator.Models.NewsRelease @{ Layout = "~/Views/Shared/_LayoutBlank.cshtml"; } @Model.Headline
I get:
[NullReferenceException: the reference to the object is not set to the instance of the object.] RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run (context ExecuteContext) in c: \ Users \ Matthew \ Documents \ GitHub \ RazorEngine \ src \ Core \ RazorEngine.Core \ Templating \ TemplateBase.cs: 139
If I delete the Layout Line, it works fine
My layout
<!DOCTYPE html> <html> <head> @RenderSection("MetaSection", false) <title>@ViewBag.Title</title> @RenderSection("HeaderSection", false) </head> <body> @RenderBody() </body> </html>
Thoughts?
source share