If you are using the Razor view engine you could declare inline functions
:
@functions {
public string DoCalculation(IEnumerable<MyItems> items) {
...
}
}
or also you could use inline helpers
:
@helper DoCalculationAndOutputResult(IEnumerable<MyItems> items)
{
foreach (var item in items)
{
<div>@item.SomeValue</div>
}
}
And if you are using the WebForms view engine:
<script type="text/C#" runat="server">
public string DoCalculation(IEnumerable<MyItems> items) {
...
}
</script>
Obviously writing C# code in views is as bad as not writing any code at all. Worth mentioning for other people reading this so that they do not do the same mistake as you.