更新时间: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