如何在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>";
}
}