Reputation: 456
I know they are anonymous types but I don't get that Razor syntax. In some documentation I found an example like this:
@Html.Label("Hello", new { htmlAtributes = new { id = "hi" }})
In most cases I just use this simple: @Html.Label("Hello", new { id = "hi" })
Help me to understand this, and I don't know why my document.getElementById('hi').innerHTML = "changed";
doesn't work with the first one.
Upvotes: 3
Views: 62
Reputation: 18973
The first way use for Html.LabelFor
@Html.LabelFor(c=>c.Email, new { htmlAtributes = new { id = "hi" } })
If you use @Html.Label("Hello", new { htmlAtributes = new { id = "hi" }})
it will generate to (with htmlatributes is an attribute of label tag)
<label for="Hello" htmlatributes="{ id = hi }">Hello</label>
You need use second way
@Html.Label("Hello", new { id = "hi" })
Upvotes: 2