// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); //Optionally call this to increase the first time render time RazorTemplateEngine.Initialize(); }
public async Task RenderView_WithModelAndViewData_WithPartialView() { //Optionally call this to create cache of the renderer //Otherwise, render time will be more than usual on first time only RazorTemplateEngine.Initialize(); // Arrange var model = new ExampleModel() { PlainText = "Lorem Ipsium", HtmlContent = "<em>Lorem Ipsium</em>" }; var viewData = new Dictionary <string, object>(); viewData["Value1"] = "1"; viewData["Value2"] = "2"; // Act var html = await RazorTemplateEngine.RenderAsync("/Views/ExampleView.cshtml", model, viewData); // Assert Assert.IsNotNull(html); Assert.IsTrue(html.Contains("Lorem Ipsium")); Assert.IsTrue(html.Contains("<em>Lorem Ipsium</em>")); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); //Optionally call this to increase the first time render time RazorTemplateEngine.Initialize(); }
static async Task Main(string[] args) { try { RazorTemplateEngine.Initialize(); System.Console.WriteLine(DateTime.Now); var model = new ExampleModel() { PlainText = "Some text", HtmlContent = "<em>Some emphasized text</em>" }; var viewData = new Dictionary <string, object>(); viewData["Value1"] = "1"; viewData["Value2"] = "2"; var html = await RazorTemplateEngine.RenderAsync("/Views/ExampleView.cshtml", model, viewData); System.Console.Write(html); System.Console.WriteLine(DateTime.Now); // Render View with View Component html = await RazorTemplateEngine.RenderAsync("/Views/ExampleViewWithViewComponent.cshtml"); System.Console.Write(html); System.Console.WriteLine(DateTime.Now); } catch (System.Exception e) { System.Console.WriteLine("{0}", e); } System.Console.ReadLine(); }
public static void Setup(TestContext context) { //Optionally call this to create cache of the renderer //Otherwise, render time will be more than usual on first time only RazorTemplateEngine.Initialize(); }
public static void AddRazorTemplating(this IServiceCollection services) { RazorViewToStringRendererFactory.ServiceCollection = services; RazorTemplateEngine.Initialize(); }