@{ var inputClass = "form-control"; var scope = ViewBag.ControllerScope as string; } @foreach (var prop in ViewData.ModelMetadata.Properties.Where(pm => pm.ShowForEdit)) { var uihit = prop.TemplateHint ?? prop.DataTypeName; var name = "query." + prop.PropertyName; if(scope=="Organ"&&prop.PropertyName=="OrganId") { @Html.Hidden(prop.PropertyName) continue; } if (prop.PropertyName == "Id" || prop.PropertyName == "DisplayOrder" || uihit == "ImageUrl" || uihit == "MultiSelectList") { continue; } else {
@if (prop.ModelType == typeof(string) || prop.UnderlyingOrModelType == typeof(Int32) || prop.UnderlyingOrModelType == typeof(Int64)|| prop.UnderlyingOrModelType == typeof(System.Single)|| prop.UnderlyingOrModelType == typeof(System.Double)|| prop.UnderlyingOrModelType == typeof(System.Decimal)) { @Html.TextBox(prop.PropertyName, null, new { name=name,@class = inputClass }) } else if(prop.IsNullableValueType&&prop.UnderlyingOrModelType == typeof(bool)) { var items=new List(){new SelectListItem{ Value="true",Text="是"},new SelectListItem{Value="false",Text="否"}}; var list = new SelectList(items, "Value", "Text"); @Html.DropDownList(prop.PropertyName, list,"请选择", new { @class = inputClass }) } else if(prop.IsNullableValueType&&prop.IsEnum) { var items=Enum.GetValues(prop.UnderlyingOrModelType).Cast() .Select(o => new SelectListItem { Value = o.GetValue().ToString(), Text = o.GetDisplayName() }) .ToList(); var list = new SelectList(items, "Value", "Text"); @Html.DropDownList(prop.PropertyName, list,"请选择", new { @class = inputClass }) } else { @Html.Editor(prop.PropertyName, prop.DataTypeName ?? prop.TemplateHint, prop.AdditionalValues) }
} }