I have a problem with the editor in Visual Studio when editing Razor Views.
I am using ASP.NET Core version 3.1.
I have the same HTML that is repeated several places, so I would like to make a function to do it.
This article describes how it should be done: 
CodePudding user response:
Ok so I found a fix. It is to put in a statement that is terminated by semicolon at the top of the function:
@{
void MakeDiv(string subtitle, string[] props, string style)
{
var a = 1; //this would fix it
<div style="@style">
<h3>@subtitle</h3>
<table>
@foreach (var e in Model.Egenskaper
.Where(e => props.Contains(e.QId)))
{
<tr>
<td>
<a href="http://#@e.QId">@e.Name</a>
</td>
<td>
@e.Value
</td>
</tr>
}
</table>
</div>};
}
}
But I guess checking if there are any props to show would make more sense. As long as the first statement in the function is not HTML, but code that is terminated by semicolon.
I am still not sure why this happens. Maybe it's because of some plugin (I am using Resharper for instance).
