Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you specify empty HTML attributes syntax in MVC helpers?

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.

like image 253
Josh Avatar asked Dec 08 '10 00:12

Josh


People also ask

What is an empty attribute in HTML?

When an HTML tag contains an attribute with no value set (indicated by no information between the quotation marks) it is said to have an "empty" attribute.

What is HTML ActionLink in MVC?

Html. ActionLink creates a hyperlink on a view page and the user clicks it to navigate to a new URL. It does not link to a view directly, rather it links to a controller's action.


2 Answers

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

like image 57
Darin Dimitrov Avatar answered Sep 19 '22 08:09

Darin Dimitrov


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

like image 31
Evan Avatar answered Sep 21 '22 08:09

Evan