Add a App_Code folder to your project and create a new CustomHelpers.cshtml file in it.
Add you custum helpers to the file, such as:
@helper Truncate(string input, int length) { if(input.Lenght <= Lenght) { @input } else { @input.Substring(0, length)<text>...</text> } }
The in order to use it in your razor views, you can do something like:
@CustomHelpers.Truncate(ViewBag.SomeMessage as string, 8)
Comments
Post a Comment