Reputation: 32088
My ViewComponent content is getting encoded for some reason, and I have not been able to find a way to render it properly.
In my view:
<vc:my-component></vc:my-component>
My component:
@model List<MyViewModel>
@foreach (var myViewModel in Model)
{
<table class="table table-bordered">
<thead class="thead-default">
<tr>
...
<th>Miércoles</th>
...
</tr>
</thead>
<tbody class="tbody-default">
...
</tbody>
</table>
}
The HTML gets rendered as:
<th>Mi�rcoles</th>
I have tried using this, but didn't make any difference:
<th>@Html.Raw("Miércoles")</th>
How can I make ASP.NET Core render the ViewComponent without encoding it?
EDIT:
The same happens with PartialViews
Upvotes: 3
Views: 1059
Reputation: 31
I had the same problem. Even placing the encode on the Layout Page, Partial View did not work.
To solve this, I had to change the file's encode as follows:
1 - Broken page
2 - Open the folder where the file is located
3 - Open the file that has the characters that break, in a notepad
4 - Click in (File -> Save As)
5 - Change encode to UTF8 and Save the file
6 - Check the result
See.. this solution also works with JavaScript.
Upvotes: 3
Reputation: 32088
This is the most stupid bug ever.
Since for new projects everything goes just fine, I decided I'd try to create a new project and copy my files. Guess what? Same problem arose. After childishly copying the text to one of the working projects, saving the file and copying the saved file to the project with problems, it worked just fine.
I find it completely weird that VS, Notepad and Notepad++ can open the file just fine, but ASP.NET Core can't.
So, solution? Copy the data over and replace the files...
Upvotes: 1