使用htmlAttributes的区别

时间:2018-10-04 06:28:18

标签: html asp.net asp.net-mvc

两者之间有什么区别

var groupDetailsArray: [String]? {
    didSet{
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let controller = storyboard.instantiateViewController(withIdentifier: "Identifier here") as? controllerHere

        controller?.grpDataArray = groupDetailsArray
    }
}

@Html.LabelFor(model => model.Soluongton, htmlAttributes: new { @class = "control-label col-md-2" })

什么是@Html.LabelFor(model => model.Soluongton, new { htmlAttributes = new { @class = "control-label col-md-2" } })

1 个答案:

答案 0 :(得分:1)

@Html.LabelFor(model => model.Soluongton, htmlAttributes: new { @class = "control-label col-md-2" })

将呈现HTML代码:

<label class="control-label col-md-2" for="Soluongton">Soluongton</label>

@Html.LabelFor(model => model.Soluongton, new { htmlAttributes = new { @class = "control-label col-md-2" } })  

将呈现HTML代码:

<label for="Soluongton" htmlAttributes="{ class = control-label col-md-2 }">Soluongton</label>

如您所见,第二个@Html.LabelFor将呈现错误的HTML输出。