ASP Net MVC - Insert html helper into string and render via Html.Raw

Asked

Viewed 79 times

1

Fala galera,

I have the following situation: I have a list of links registered in the database, which will be loaded according to the user’s profile.

I’m currently obligated to do so:

@Html.Raw(listaMenusSistema[i].HtmlMenu);

This will bring me the result:

<li class="teste"><a href="/">login</a></li>

But I would like to use Html.Actionlink, to facilitate the maintenance of the links. So I would have in the database:

<li class="teste">@Html.ActionLink("login", "login", "home", new { area = "" }, null)</li>

to produce the same result.

It turns out that if I bring this string from the database, Razor does not interpret html helper in the middle of the string, and will generate html:

<li class="teste">@Html.ActionLink("login", "login", "home", new { area = "" }, null)"</li>

instead of the correct, which would be the same above:

<li class="teste"><a href="/">login</a></li>

Does anyone know how to solve or has any idea ?

Thanks.

Jonah

  • Good afternoon, any ideas? Thanks ...

  • You have to bring in the list listaMenusSistema the decryptions of the menu items and not the html of the item. And you can make a loop with @foreach and write with the @Hmlt.ActionLink within the <li tags> .

No answers

Browser other questions tagged

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