How to display Razor helper code that is inside a variable?

We are trying to build the form dynamically using the code that is stored in the database. Depending on what controls we want to use for a particular form, we put them in a list and pass them in our opinion.

Inside the view, we look at a list that displays code for each; however when i do the following

foreach(var control in Model.ParameterControls)
{
     @control.code
}

I just get the code output in ", which displays the code itself on the screen instead of rendering the control. How to take a control, for example, @ Html.Textbox (" title ") or @ Html.DevExpress (). TextBox (" Title ") and get it to display from a variable?

Edit

ParameterControls is defined as follows

    List<ControlModel> ParameterControls

Where is the ControlModel:

    public string Title { get; set; }
    public string ControlName { get; set; }
    public ParameterType Type { get; set; }
    /* additional irrelevant properties removed */

And ParameterType:

    public int TypeID { get; set; }
    public string TypeName { get; set; }
    public string TypeCode { get; set; }

TypeCode (..)

     @Html.DevExpress().TextBox("Test").GetHtml()
+3
2
foreach(var control in Model.ParameterControls)
{
    <text>@control.code</text>
}
+1

, @Html.Textbox( "title" ) @Html.DevExpress(). TextBox ( "" ) ?

, Parse Razor String varialbe , Html , , , RazorEngine.

Razor -

  Razor.SetTemplateBase(typeof(HtmlTemplateBase<>));

  string template = 
  @"<html>
      <head>
        <title>Hello @Model.Name</title>
      </head>
      <body>
        Email: @Html.TextBoxFor(m => m.Email)
      </body>
    </html>";

  var model = new PageModel { Name = "World", Email = "someone@somewhere.com" };
  string result = Razor.Parse(template, model);
0

All Articles