.Net MVC Html Helper Example

Posted: May 8th, 2010 | Author: | Tags: , , , | No Comments »
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
using System;
using System.Web.Mvc;
 
namespace MvcApplication1.Helpers
{
     public static class HtmlHelperExtensions // needs to be a static class
     {
          public static string MyHelper(this HtmlHelper helper, string arg1, string arg2)
          {
                string output = string.Empty();
               // do stuff
               return output; // return a string
          }
     }
}

And don’t forget import the Namespace in your view!

1
<%@ Import Namespace="MvcApplication1.Helpers" %>