Created
October 27, 2017 09:36
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @* | |
| * 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()); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @* | |
| * 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