是否可以将@ html.EditorFor与ViewData.ModelMetadata.Properties一起使用

时间:2015-05-20 03:42:44

标签: asp.net-mvc html-helper

当我循环浏览属性时,是否仍然在编辑器模板中使用@html.editorfor和其他类似帮助器?

请注意我正在使用Kendo Grid。 Kendo使用Html.EditorForModel()生成编辑和创建模态窗口。我不想要默认布局,也应该以不同的方式显示某些属性,例如使用不同的元素。所以,我正在尝试为我的模型创建自定义编辑器模板,并以我想要的方式呈现属性。

这是编辑模板:

@using System.Collections
@model Models.ClassName

@{int i = 0;}
<div class="form-group form-inline col-xs-12">
    @foreach (var property in ViewData.ModelMetadata.Properties)
    {
        //filtering navigation and computational properties
        if (property.PropertyName.StartsWith("Z") || property.IsReadOnly))
        {
            continue;
        }
        switch (property.PropertyName)
        {
            case "pro3":
                @Html.Hidden(property.PropertyName, "-1")
                continue;
            case "LiIdPeriod":
                <div class="col-xs-5">
                    @Html.Label(property.DisplayName, new { @for = property.PropertyName, @class = "control-label col-xs-3" })
                    @Html.DropDownList(property.PropertyName, new SelectList((IEnumerable)ViewData["Years"], "Id", "Text"))
                </div>
                break;
            default:
            <div class="col-xs-5">
                @Html.Label(property.DisplayName, new { @for = property.PropertyName, @class = "control-label col-xs-3" })
                @Html.TextBox(property.PropertyName, new { @class = "form-control" })
            </div>
                break;
        }
        if (++i % 2 == 0)
        {
            @:</div><div class="form-group form-inline col-xs-12">
        }
    }
</div>

0 个答案:

没有答案