我知道它们是匿名类型,但我不理解Razor语法。在一些文档中,我找到了一个类似以下的示例:
@Html.Label("Hello", new { htmlAtributes = new { id = "hi" }})
在大多数情况下,我只使用这个简单的代码:@Html.Label("Hello", new { id = "hi" })
请帮助我理解这一点,我不知道为什么我的document.getElementById('hi').innerHTML = "changed";不能与第一个一起工作。
发布于 2019-05-01 10:58:04
用于Html.LabelFor的第一种方法
@Html.LabelFor(c=>c.Email, new { htmlAtributes = new { id = "hi" } })如果您使用@Html.Label("Hello", new { htmlAtributes = new { id = "hi" }})
它将生成to (其中htmlatributes是标签标签的属性)
<label for="Hello" htmlatributes="{ id = hi }">Hello</label>你需要走第二条路
@Html.Label("Hello", new { id = "hi" })https://stackoverflow.com/questions/55930965
复制相似问题