asp.net MVC model binding with reflection

隐身守侯 提交于 2020-01-07 01:22:34

问题


You see my dilemma here. It's with the binding x => property.Name. So normally you would do something like x=> x.someproperty. But I'm using reflection so I can't do it that way. I tried a number of things. Using the viewdata to find the property. Doesn't like that. Any thoughts on the matter?

foreach (var property in Model.GetType().GetProperties())
{
    <div class="row">
        <div class="col-md-2">
            <label>@(property.Name ?? property.Name)</label>
        </div>
        <div class="col-md-2">
            @Html.TextBoxFor(x => property.Name, new { @id = property.Name})
        </div>
    </div>
}

来源:https://stackoverflow.com/questions/32282863/asp-net-mvc-model-binding-with-reflection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!