这样不行,错误是:
Expected ","
@Html.LabelFor(ViewBag.OrganizationDetails => (string)ViewBag.OrganizationDetails.AddressLegal, htmlAttributes: new { @class = "control-label col-md-2" })
OrganizationDetails
是一个类,AddressLegal
是一个字符串(需要其值)
最佳答案
试试这个:
@model ParentModel
@Html.LabelFor(model => model.Name)
@Html.LabelFor(model => model.Child.Name)
在你的情况下应该是:
@model ViewBag.OrganizationDetails
@Html.LabelFor(model => model.AddressLegal, new { @class = "control-label col-md-2" })
或
@model ViewBag
@Html.LabelFor(model => model.OrganizationDetails.AddressLegal, new { @class = "control-label col-md-2" })
我没试过。
关于c# - 如何将复杂类型传递给 Html.LabelFor?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68826212/