7

I'm curious... can you specify an HTML attribute that is empty or valueless? The W3 spec allows for empty attributes like so: <input type="checkbox" disabled checked>

And with MVC, you declare inputs like this:Html.CheckBoxFor(m=>m.Foo). You can add Html Attributes with the Html.CheckBoxFor(m=>m.Foo, new {@class="myCssClass"}) syntax, but you can't do Html.CheckBoxFor(m=>m.Foo, new { disabled, checked})

I know the spec also allows for self-value attributes for these kinds (e.g. new {disabled="disabled"}) and empty string values (e.g. new {disabled=""}).

I'm just curious if there is any way to specify the empty syntax.

1

3 Answers 3

2

Late to the party, but ... this from w3schools:

"In XHTML, attribute minimization is forbidden, and the disabled attribute must be defined as: select disabled="disabled".

So for compliance, don't even try to use attribute minimization? But it seems the HTML helpers don't allow it anyway.

http://www.w3schools.com/tags/att_select_disabled.asp

Sign up to request clarification or add additional context in comments.

Comments

1

No, standard HTML helpers doesn't support this. You could write a custom HTML helper and build the markup yourself.

Comments

1

Yes, you can. Set it to string.Empty and MVC5 will render an empty attribute.

new { disabled = string.Empty }

And yes, the HTML5 spec does allow empty attributes perfectly. XHTML is outdated.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.