如何从实体类型生成剃刀视图中的菜单项

时间:2015-05-03 17:07:39

标签: asp.net-mvc asp.net-mvc-4 razor html-helper razor-2

如何在ASP.NET MVC 4 Razor视图中从实体类型生成菜单项html,如

@(Html.LiEntity<Customer>())

我根据Is it possible to create a generic @helper method with Razor?

中的回答尝试了以下代码

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

中发表评论

但是没有定义关于Url的编译错误。

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>";
    }
}

0 个答案:

没有答案