Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ps-team/45ffc947dc22fc65711e2b2f99f9a6b0 to your computer and use it in GitHub Desktop.
Save ps-team/45ffc947dc22fc65711e2b2f99f9a6b0 to your computer and use it in GitHub Desktop.
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 : /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());
}
}
@*
* 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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment