且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

asp.net MVC3剃须刀:基于用户角色显示的ActionLink

更新时间:2023-02-26 08:13:43

我在过去创造了一个辅助函数来只有当条件满足这样返回的输出:

I have in the past created a helper function to only return output when a criteria is met like this:

public static MvcHtmlString If(this MvcHtmlString value, bool evaluation)
{
     return evaluation ? value : MvcHtmlString.Empty;
}

所以你可以使用这样的:

so you can use this:

@Html.ActionLink("Create New", "Create").If(User.IsInRole("Administrators"))

这事情是这样的清晰,短

This way it is legible and short