I'm pretty new to .NET Core (ASP.NET on the whole) and I was wondering if I'm doing anything obviously wrong when trying to create a C# function inside my View
my view is as follows (Collections.cshtml)
<h2>Collections</h2>
<div id="content">
@{
// define variables
List<string> collections;
int counter;
// build list
collections = new List<string>();
collections.Add("Nothing 01");
collections.Add("Nothing 02");
// display list
counter = 0;
while(counter < collections.Count)
{
<p>@collections[counter]</p>
counter = counter + 1;
}
}
</div>
That all works fine and does what I want it to do but if I try to organize it into functions or even add a basic function it breaks like bellow
@{
// function for no reason
public void testFunc()
{
string nothing;
nothing = null;
return;
}
}
<h2>Collections</h2>
<div id="content">
@{
// define variables
List<string> collections;
int counter;
// build list
collections = new List<string>();
collections.Add("Nothing 01");
collections.Add("Nothing 02");
// display list
counter = 0;
while(counter < collections.Count)
{
<p>@collections[counter]</p>
counter = counter + 1;
}
}
</div>
Just adding that function breaks it and I'm not sure why