@using System @using System.Linq @{ var inputClass = "form-control"; var scope = ViewBag.ControllerScope as string; } @foreach (var prop in ViewData.ModelMetadata.Properties.Where(pm => pm.ShowForEdit)) { var metadata = prop as Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadata; object propValue = Model == null ? (prop.ModelType.IsValueType ? Activator.CreateInstance(prop.ModelType) : null) : ViewData.ModelMetadata.ModelType.GetProperty(prop.PropertyName).GetValue(ViewData.Model); if(scope=="Organ"&&prop.PropertyName=="OrganId") { @Html.Hidden(prop.PropertyName) continue; } if (prop.HideSurroundingHtml) { @Html.Hidden(prop.PropertyName) } else { var uihit = prop.TemplateHint ?? prop.DataTypeName; var isRequired = prop.IsRequired && prop.ModelType != typeof(bool); var htmlClass = "col-sm-2 col-form-label"; htmlClass += isRequired ? " required" : "";
@Html.Label(prop.PropertyName, prop.GetDisplayName() + ":", new { @class = htmlClass })
@if (metadata.Attributes.Attributes.Any(o => o.GetType() == typeof(System.ComponentModel.ReadOnlyAttribute))) {
@Html.Hidden(prop.PropertyName) @Html.Display(prop.PropertyName, prop.DataTypeName ?? prop.TemplateHint)
} else if (!string.IsNullOrEmpty(uihit) && !(uihit == "EmailAddress" || uihit == "PhoneNumber")) { @Html.Editor(prop.PropertyName, prop.DataTypeName ?? prop.TemplateHint, prop.AdditionalValues) } else { if (prop.ModelType == typeof(string)) { if (prop.DataTypeName == System.ComponentModel.DataAnnotations.DataType.Password.ToString()) { @Html.Password(prop.PropertyName, null, new { @class = inputClass }) } else if (prop.DataTypeName == System.ComponentModel.DataAnnotations.DataType.MultilineText.ToString()) { @Html.TextArea(prop.PropertyName, null, new { @class = inputClass }) } else { @Html.TextBox(prop.PropertyName, null, new { @class = inputClass }) } } else if (prop.ModelType == typeof(bool) || prop.UnderlyingOrModelType == typeof(bool)) {
@Html.CheckBox(prop.PropertyName, new { style = "width:20px;height:20px;" })
} else { @Html.TextBox(prop.PropertyName, null, new { @class = inputClass }) } } @Html.ValidationMessage(prop.PropertyName, new { @class = "text-danger" })
@{ if (metadata != null) { var attr = metadata.Attributes.Attributes.OfType().FirstOrDefault() as System.ComponentModel.DescriptionAttribute; if (attr != null && attr.Description != null) { @attr.Description } } }
} }