Skip to content

Instantly share code, notes, and snippets.

@JustLikeIcarus
Last active December 15, 2015 20:40
Show Gist options
  • Select an option

  • Save JustLikeIcarus/5320087 to your computer and use it in GitHub Desktop.

Select an option

Save JustLikeIcarus/5320087 to your computer and use it in GitHub Desktop.
Extend MVC Html Helpers to return if an evaluation returns true. Example: @Html.ActionLink("Test Link", "SomeAction", "SomeController").If(Roles.GetRolesForUser().Contains("Admin"))
namespace System.Web.Mvc
{
public static class HelperExtensions
{
public static MvcHtmlString If(this MvcHtmlString value, bool evaluation)
{
return evaluation ? value : MvcHtmlString.Empty;
}
}
}
@jredh

jredh commented Dec 3, 2014

Copy link
Copy Markdown

This is pretty cool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment