toddams / RazorLight

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

Compile render string without model #543

Closed vanillajonathan closed 2 hours ago

vanillajonathan commented 5 months 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);
toddams commented 2 hours ago

Vision is to prefer model over ViewBag and other dynamic transport, we won't change API for it, sorry