You can create your own MVC Helper method. To create a public static class MyRenderHelpers in the System.Web.Mvc.Html and write the Html method.
namespace System.Web.Mvc.Html { public static class MyRenderHelpers { public static MvcHtmlString Html(this HtmlHelper helper, string html, bool condition) { if (condition) return MvcHtmlString.Create(html); else return MvcHtmlString.Empty; } } }
Now you can use this extension method in your razor:
@Html.Html("<div>", somecondition)
Thomas Hauser Apr 15 2018-12-12T00: 00Z
source share