Question: I want to create a helper method that I can imagine has a signature similar to this:

```
public static MyHtmlTag GenerateTag<T>(this HtmlHelper htmlHelper, object obj)
{
    // how do I create an instance of MyAnchor? 
    // this returns MyAnchor, which has a MyHtmlTag base
}

```

When I invoke the method, I want to specify a type of MyHtmlTag, such as MyAnchor, e.g.:

```
<%= Html.GenerateTag<MyAnchor>(obj) %>

```

or

```
<%= Html.GenerateTag<MySpan>(obj) %>

```

Can someone show me how to create this method?

Also, what's involved in creating an instance of the type I specified? `Activator.CreateInstance()`?

Thanks 

Dave

Answer: 
There's existing functionality in [MvcContrib](http://mvccontrib.codeplex.com) you may want to check out called "[FluentHtml](http://lunaverse.wordpress.com/2008/11/24/mvcfluenthtml-fluent-html-interface-for-ms-mvc/)". It looks like this:

```
<%=this.TextBox(x => x.FirstName).Class("required").Label("First Name:")%>
<%=this.Select(x => x.ClientId).Options((SelectList)ViewData["clients"]).Label("Client:")%>
<%=this.MultiSelect(x => x.UserId).Options(ViewModel.Users)%>
<%=this.CheckBox("enabled").LabelAfter("Enabled").Title("Click to enable.").Styles(vertical_align => "middle")%>

```
You need to add the generic constraint of [new()](http://msdn.microsoft.com/en-us/library/sd2w2ew5(VS.80).aspx) to T, then do the following:

```
public static MyHtmlTag GenerateTag<T> (this HtmlHelper helper, T obj) where T : MyHtmlTag, new()
{
    T val = new T ();
    return val;
}

```