3
Vote

Add support for conditional attributes in the Html helpers

description

Today, if a user puts the following in a CSHTML page:
@Html.TextBox("myname", "mytext", new { disabled = isDisabled })
this will render a "disabled" attribute whose value will be set to True or False. This is inconsistent with HTML's handling of boolean attributes, and it's also inconsistent with the work we did in Razor v2 to support conditional attributes in Razor markup.

This suggestion is to add conditional attribute logic to the Html helpers so the above would conditionally display the disabled attribute (provided that isDisabled is a boolean).

comments

Meryovi wrote Tue at 5:46 PM

I think this should also handle null values as asked in this StackOverflow question.