0
我循环周围ViewData.ModelMetadata.Properties
渲染某些输入这些属性:是否可以从ModelMetaData.Properties动态创建输入字段?
@foreach (var property in ViewData.ModelMetadata.Properties
.Where(p => (p.AdditionalValues.Count > 0) && ((bool)p.AdditionalValues["tags"])))
{
// Generate form here
}
我能够与
@Html.LabelFor(model => Model,
property.DisplayName,
htmlAttributes: new { @class = "control-label col-md-2" })
正确显示LabelFor
但我似乎无法得到的编辑工作。
我试图
@Html.HiddenFor(model => model.GetType().GetProperties().First(t=>t.Name == property.PropertyName))
但我看到了这个错误:
Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.
我也试过
@Html.HiddenFor(model => property)
但随后的价值在于通过为null
控制器
是否可以这样做,还是我需要手动编码每个输入?