Question

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?

Was it helpful?

Solution

Modify your markup:

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

The equals sign and no semicolon should do the trick.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top