When using an HTML Helper, what is the best method to set an attribute based on a condition. For example
<%if (Page.User.IsInRole(\"administrator\")) {%&g
You'll need to pass a Dictionary
, and add the disabled
key inside an if
statement.
I recommend making an overload of the extension method that takes a bool disabled
parameter and adds it to a RouteValueDictionary created from the attributes parameter if it's true
. (You could also remove the disabled
entry from the RouteValueDictionary
if it's false
, and not take another parameter)