A very basic example of how the app_code folder can be used to create and home re-usable functions that razorviews can then use. These can use either be .cs or .cshtml files.
@*
* FILE : /SiteElements/Razorviews/MyRazorview.cshtml
*@
@{
@*
* NOTES
* *****
* To call functions we refer to the file name and function name:
*
* Example : FileName.FunctionName();
*@
string string1 = "This is a string of some sort";
string string2 = StringFunctions.Encode(string1);
<p>@string2</p> // would print : this+is+a+string+of+some+sort
}
@*
* FILE : /App_Code/StringFunctions.cshtml
*@
@functions
{
@*
* FUNCTION : ENCODE STRING
* ************************
* Description : takes an input string and returns it lower-cases and url-encoded
*
* Example use : building custom urls and/or query-strings
*@
public static string Encode(string value)
{
return HttpUtility.UrlEncode(value.ToLower());
}
}