Solution 1 :

The problem appears to be the space in your Icon string, “fas fa-file”. The View when it renders is reading the space as its signal to close the quote. I have experienced this manually editing Views in the IDE. I have no definite solution, but a couple of things you might try.

First, try breaking up the string in your foreach loop, like this:

<a><i class="@action.Icon.Split(' ')[0] @action.Icon.Split(' ')[1]"></i></a>

If that doesn’t work, you might try escaping the space in the original string, like this:

"fas fa-file".

Problem :

Working with ASP.NET Core, I have a viewmodel with a string property Icon = “fas fa-file”.
My razor view looks like this:

    @foreach (var action in Model.DashboardIconActions)
      <a><i class="@action.Icon"></i></a>

In the generated HTML, I get:

<i class="fas" fa-file="" aria-hidden="true"></i>

So of course, my icon does not appear. Does anyone know what might go wrong here?

Thanks in advance and greetings from Belgium!