0
我为Northwinds DB's product
表创建了脚手架视图。我了解到它正在创建匿名类型new {@class...
。但是,我不明白以下代码中的部分htmlAttributes:
。它在做什么?htmlAttributes:在Html.LabelFor中
@Html.LabelFor(model => model.UnitsInStock,
htmlAttributes: new { @class = "control-label col-md-2" })
它和new { htmlAttributes = new { @class = "form-control" }
这个代码有什么不同?我希望我能正确地问问题。我使用MVC 5与Visual Studio 2015
它只是使'新{@class = “控制标签COL-MD-2”}'目的是扩展方法的'htmlAttributes'参数。你也可以使用'@ Html.LabelFor(model => model.UnitsInStock,new {@class =“control-label col-md-2”})'(即不显式使用'htmlAttributes:' –
)参数功能在C#? –
..进一步阐明html属性是使用命名参数'htmlAttributes:'传递的。这是C#中的一个很棒的功能。更多信息https://msdn.microsoft.com/en-us/library/dd264739.aspx – niksofteng