We can create the Html Helper using Razor declaration syntax like this
Step 1: In App_Code folder add new razor view form i.e CustomHelper.cshtml and write the reusable helper method like this
@helper Truncate(string input, int length) { if (input.Length <= length) { @input } else { @input.Substring(0, length)<text>........ </text> } }
Step 2: Call the Html hepler in View page of application like this
@{ ViewBag.Title = "Index"; } <b>Htmlhelper using Razor declaration Helper Sysntax </b> <br /> <br /> @CustomHelper.Truncate(@ViewBag.Message as string, 7)