1

How to generate menu item html in ASP.NET MVC 4 Razor view from entity type like

@(Html.LiEntity<Customer>())

I tried code below based on answer in Is it possible to create a generic @helper method with Razor?

and in comment in https://stackoverflow.com/questions/30011675/how-to-get-type-attribute-in-razor

but got compile error about Url is not defined.

public static class LiEntityHelper
{
    public static string LiEntity<TEntity>()
        where TEntity : EntityBase
    {
        return @"<li><a href='" + Url.Action("Index", "Home", new
                {
           _user = Thread.CurrentPrincipal.Identity.Name
              }) +
            @"'><i class='glyphicon glyphicon-bar-chart></i>
     <span>" + LocalizableDisplayNameAttributeI.Get<TEntity>() + @"</span></a></li>";
    }
}
Community
  • 1
  • 1
Andrus
  • 26,339
  • 60
  • 204
  • 378

0 Answers0