toddams / RazorLight

Template engine based on Microsoft's Razor parsing engine for .NET Core
Apache License 2.0
1.51k stars 261 forks source link

Compile render string without model #543

Open vanillajonathan opened 1 month ago

vanillajonathan commented 1 month ago

Is your feature request related to a problem? Please describe. I would just like to use a view bag without any model.

Describe the solution you'd like I want the model parameter in the CompileRenderStringAsync method to be optional. So I can do:

var template = "Hello, @Model.Name. Welcome to RazorLight repository";
var viewBag = new ExpandoObject();
viewBag.TryAdd("Name", "John Doe");

string result = await engine.CompileRenderStringAsync("templateKey", template, null, viewBag);