public class T_BlogPost
{
public string BP_UID;
public string BP_Title;
public string BP_HtmlContent;
}
public class ViewModel
{
public string Name;
public T_BlogPost BlogPost;
}
Then I want to compile Index.cshtml:
RazorLightEngine engine = new RazorLightEngineBuilder()
.UseFileSystemProject(@"D:/username/Documents/Visual Studio 2017/Projects/RazorLight/TestRazorLight/Views")
// .UseEmbeddedResourcesProject(typeof(Program)) // exception without this
.UseMemoryCachingProvider()
.Build();
ViewModel model = new ViewModel { Name = "John Doe", BlogPost= new T_BlogPost() { BP_UID="hoo", BP_Title="Foobar", BP_HtmlContent="<h1>Hello</h1>" } };
string result = await engine.CompileRenderAsync("Home/Index.cshtml", model);
System.Console.WriteLine(result);
with Index.cshtml having this content:
@*
For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@model TestRazorLight.ViewModel
@{
Layout = null;
}
Hello, @Model.Name. Welcome to RazorLight repository
@Html.DisplayFor(m => m.BlogPost)
and /DisplayTemplates/T_BlogPost.cshtml having this content:
How does this work with DisplayTemplates on the file system ? e.g. i have this directory structure
And these dummy classes
Then I want to compile Index.cshtml:
with Index.cshtml having this content:
and /DisplayTemplates/T_BlogPost.cshtml having this content:
The only thing I get is an exception "The name 'HTML' does not exist in the current context".