How to read tags inside a string?

Asked

Viewed 73 times

0

I’m developing a code on. NET Core Razor Pages, and in part, I would like to create a list of items according to data that I am already picking up there...

My Code: (Arquivo.Cs)

var descr = "<ul>";

for (int i = 1; i < 9; i++)
{
     descr += "<li>" + result.vfp.descricao[i].desc + "</li>";
}
descr += "</ul>";

HttpContext.Session.SetString("xmltojson", descr);

(cshtml file):

<div class="card menu-card">
    <div class="card-body">
         <center><h4> @HttpContext.Session.GetString("xmltojson")</h4></center>
    </div>
</div>

RESULT:

inserir a descrição da imagem aqui

He’s writing the tags, instead of putting them together, someone can help me?

  • @Html.Raw(HttpContext.Session.GetString("xmltojson")) wouldn’t be like this?

1 answer

0

To take a string and render as HTML use Razor’s @Html.Raw.

Example:

@Html.Raw(HttpContext.Session.GetString("xmltojson"))
  • I think you missed something in your example

  • 1

    @I edited the question correcting the example.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.