toddams / RazorLight

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

Use HtmlHelper from view #342

Open jzabroski opened 4 years ago

jzabroski commented 4 years ago

Re-open #22

Users want to be able to use HtmlHelper and @Html.Raw syntax from razor light models.

@martinalderson @jmevel @bjcull @jjxtra

ElementalLogic commented 3 years ago

@HTML.Raw is flawed anyway.

Better practice to use HtmlString. So my workaround is to directly from your RazorView you can call @(new Microsoft.AspNetCore.Html.HtmlString("test"))

Probably nicer to wrap that up in an extension:

public static class Html { public static HtmlString Raw(string source) { return new HtmlString(source); } }

then you can call @Html.Raw("test") from inside your templates..