views:

41

answers:

1

I'm trying to create a custom HTML Helper to help simplify my masterpages menu, however it is not rendering on the HTML when I use it.. I'm thinking I will need to create a partial view, any ideas?

I did this..

    public static string CreateAdminMenuLink(this HtmlHelper helper, string caption, string link)
    {
       var lnk = TagBuilder("a");
       lnk.SetInnerText(caption);
       lnk.MergeAttribute("href", target);
       return lnk.ToString(TagRenderMode.SelfClosing);
    }

Now in my View, i have

<% Html.CreateAdminMenuLink("Home", "~/Page/Home"); %>

Thanks: Dave Swersky

Fix was: I forgot the equals and removed the semi-colon

<%= Html.CreateAdminMenuLink("Home", "~/Page/Home") %> 

but when I look at the source, its empty.. tried adding <% using (Html.BeginForm()) %> and it adds a form.. but the link still doesnt come up.. debugged and the string works when i look at the watch, but does not render..

Any ideas?

+2  A: 

Modify your markup:

<%= Html.CreateAdminMenuLink("Home", "~/Page/Home") %>

The equals sign and no semicolon should do the trick.

Dave Swersky
Ha! It is always the small things I miss.. appreciate it, worked fine now! :)
LeeHull
Glad I could help :)
Dave Swersky