I am confused about which is which. Can someone explain the difference between the two.
For example is the following which returns a MvcHtmlString an extension or a helper method?
public static class LinkExtensions
{
public static MvcHtmlString HdrLinks(
this HtmlHelper helper,
string topLink,
string subLink,
System.Security.Principal.IPrincipal user)
{
etc ...
How about this:
public static class Slug
{
public static string Generate(string phrase, int maxLength = 50)
{
string str = RemoveAccent(phrase).ToLower();
str = Regex.Replace(str, @"[^a-z0-9\s-]", " ");
str = Regex.Replace(str, @"[\s-]+", " ").Trim();
str = str.Substring(0, str.Length <= maxLength ? str.Length : maxLength).Trim();
str = Regex.Replace(str, @"\s", "-");
return str;
}
They are not helper methods, they are called HTML helpers.There is no ‘helper method’ implementation in C#. HTML helpers are implemented as extension methods. You can see extension methods are static methods with a this clause before first parameter. HTML helpers makes it easier to generate html tags.