|
|
@using System
|
|
|
@using System.Linq
|
|
|
@{
|
|
|
var inputClass = "form-control";
|
|
|
}
|
|
|
@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) : null;
|
|
|
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" : "";
|
|
|
<div class="form-group row">
|
|
|
@if (prop.ModelType != typeof(bool))
|
|
|
{
|
|
|
@Html.Label(prop.PropertyName, prop.GetDisplayName() + ":", new { @class = htmlClass })
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
<div class="col-sm-2"></div>
|
|
|
}
|
|
|
<div class="col-sm-8">
|
|
|
@if (metadata.Attributes.Attributes.Any(o => o.GetType() == typeof(System.ComponentModel.ReadOnlyAttribute)))
|
|
|
{
|
|
|
|
|
|
<div class="form-control form-control-display">
|
|
|
@Html.Hidden(prop.PropertyName)
|
|
|
@Html.Display(prop.PropertyName, prop.DataTypeName ?? prop.TemplateHint)
|
|
|
@if (prop.ModelType == typeof(bool))
|
|
|
{
|
|
|
@Html.Label(prop.PropertyName, prop.DisplayName + ":", new { @class = "form-check-label" })
|
|
|
}
|
|
|
</div>
|
|
|
}
|
|
|
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))
|
|
|
{
|
|
|
<div class="form-group">
|
|
|
<div class="form-check">
|
|
|
@Html.CheckBox(prop.PropertyName, new { @class = "form-check-input" })
|
|
|
@Html.Label(prop.PropertyName, prop.DisplayName + ":", new { @class = "form-check-label" })
|
|
|
</div>
|
|
|
</div>
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@Html.TextBox(prop.PropertyName, null, new { @class = inputClass })
|
|
|
}
|
|
|
}
|
|
|
@Html.ValidationMessage(prop.PropertyName, new { @class = "text-danger" })
|
|
|
</div>
|
|
|
<div class="col-sm-2">
|
|
|
@{
|
|
|
if (metadata != null)
|
|
|
{
|
|
|
var attr = metadata.Attributes.Attributes.OfType<System.ComponentModel.DescriptionAttribute>().FirstOrDefault() as System.ComponentModel.DescriptionAttribute;
|
|
|
if (attr != null && attr.Description != null)
|
|
|
{
|
|
|
<span class="form-control form-control-display">@attr.Description</span>
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
</div>
|
|
|
</div>
|
|
|
}
|
|
|
} |