I'm using @:</div>
to display some bootstrap columns correctly. This is the my code where i'm using it:
var i = 0;
<div class="container-fluid">
<div class="row show-grid">
@foreach (var one in Model)
{
if (i % 3 == 0)
{
@:<div class="row show-grid">
}
<div class="one-element col-md-4">
@one.Title
</div>
if ((i + 1) % 3 == 0)
{
@:</div>
}
i++;
}
</div>
</div>
It formats this (which works fine as long as i don't use the VisualStudio
auto-format feature):
@:</div>
to this:
@:
</div>
And then the application doesn't work anymore.
How can this be fixed?
On Windows Shift + Alt + F. On macOS Shift + Option + F. On Linux Ctrl + Shift + I.
Auto formatting settings in Visual Studio Show activity on this post. Select the text you want to automatically indent. Click menu Edit → Advanced → *Format Selection, or press Ctrl + K , Ctrl + F . Format Selection applies the smart indenting rules for the language in which you are programming to the selected text.
The code formatting is available in Visual Studio Code through the following shortcuts: On Windows Shift + Alt + F. On Mac Shift + Option + F. On Linux Ctrl + Shift + I.
VS Code has great support for source code formatting. The editor has two explicit format actions: Format Document (Ctrl+Shift+I) - Format the entire active file. Format Selection (Ctrl+K Ctrl+F) - Format the selected text.
I fixed it by using @Html.Raw()
like this:
var i = 0;
<div class="container-fluid">
<div class="row show-grid">
@foreach (var one in Model)
{
if (i % 3 == 0)
{
@Html.Raw("<div class=\"row show-grid\">")
}
<div class="one-element col-md-4">
@one.Title
</div>
if ((i + 1) % 3 == 0)
{
@Html.Raw("</div>")
}
i++;
}
</div>
</div>
I guess that this is as good as it gets.
But if anyone knows of a more elegant way to do it, please let me know.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With