I want to use a simple function like this in my ASP.NET MVC View. It takes an integer parameter and returns a string.
Function FileSizeString(ByVal ByteCount As Integer) As String
Select Case ByteCount
Case Is < (2 ^ 10)
Return ByteCount.ToString("N0") + "B"
Case (2 ^ 10) To ((2 ^ 20) - 1)
Return (ByteCount / (2 ^ 10)).ToString("N0") + "KB"
Case (2 ^ 20) To ((2 ^ 30) - 1)
Return (ByteCount / (2 ^ 20)).ToString("N0") + "MB"
Case (2 ^ 30) To Integer.MaxValue
Return (ByteCount / (2 ^ 30)).ToString("N0") + "GB"
End Select
End Function
I've got it in my Controller, but I cannot execute it from within my View. This produces the compile-time error "Name 'FileSizeString' is not declared."
<ul>
<% For Each d As Document In Model.Attachments%>
<li>
<a href="<%=Url.RouteUrl("Download", New With {.id = a.Id}) %>">
<%=d.FileName %> (<%=FileSizeString(d.FileSize) %> bytes)
</a>
</li>
<% Next %>
</ul>
Where do I need to put my function? How do I make my View able to access it?