开发者

How can I render a razor view to a string without dependency on a controller context?

开发者 https://www.devze.com 2023-02-16 04:53 出处:网络
How can I render a razor view to a string without dependency on a controller context? All the examples I have seen involve passing in a ControllerContext to my render helper class.However, I don\'t w

How can I render a razor view to a string without dependency on a controller context?

All the examples I have seen involve passing in a ControllerContext to my render helper class. However, I don't wa开发者_如何学Cnt the dependency to the controller context as I want the rendered string to be generated inside a service.


RazorEngine seems to do exactly what you're looking for:

string template = "Hello @Model.Name! Welcome to Razor!";
string result = Razor.Parse(template, new { Name = "World" });
0

精彩评论

暂无评论...
验证码 换一张
取 消