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

1

Talk to people,

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 forced to do this:

@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 make it easier to maintain links. So I would have it 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 get the string from the bank, the razor does not interpret the html helper in the middle of the string, and will generate the html:

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

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

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

Does anyone know how to solve or have any ideas?

Thanks.

Jonas

    
asked by anonymous 29.08.2018 / 20:06

0 answers