Last active
December 15, 2015 20:40
-
-
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"))
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace System.Web.Mvc | |
{ | |
public static class HelperExtensions | |
{ | |
public static MvcHtmlString If(this MvcHtmlString value, bool evaluation) | |
{ | |
return evaluation ? value : MvcHtmlString.Empty; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is pretty cool!