Former-commit-id: b931c1232a5c462765897c316f5de98752c3f2eb
Former-commit-id: 37d818ed138ff5ca9260355ced6513cdffbcd9e2
TSXN
wanggang 5 years ago
parent a06ec4d76e
commit 0f9c5fa966

@ -4,11 +4,18 @@
@foreach (var prop in ViewData.ModelMetadata.Properties.Where(pm => pm.ShowForEdit && !pm.HideSurroundingHtml)) @foreach (var prop in ViewData.ModelMetadata.Properties.Where(pm => pm.ShowForEdit && !pm.HideSurroundingHtml))
{ {
var uihit = prop.DataTypeName ?? prop.TemplateHint; var uihit = prop.DataTypeName ?? prop.TemplateHint;
<div class="form-group row"> <div class="form-group row" title="@uihit">
@Html.Label(prop.PropertyName, prop.GetDisplayName() + "", new { @class = "col-sm-2 col-form-label" }) @Html.Label(prop.PropertyName, prop.GetDisplayName() + "", new { @class = "col-sm-2 col-form-label" })
<div class="col-sm-8"> <div class="col-sm-8">
<div class="form-control form-control-display"> <div class="form-control form-control-display">
@Html.Display(prop.PropertyName, prop.DataTypeName ?? prop.TemplateHint) @if (prop.UnderlyingOrModelType == typeof(bool))
{
@Html.CheckBox(prop.PropertyName, new { disabled = "disabled", style = "width:20px;height:20px;margin:2px 0;" })
}
else
{
@Html.Display(prop.PropertyName, uihit)
}
</div> </div>
</div> </div>
</div> </div>

@ -6,7 +6,7 @@
@foreach (var prop in ViewData.ModelMetadata.Properties.Where(pm => pm.ShowForEdit)) @foreach (var prop in ViewData.ModelMetadata.Properties.Where(pm => pm.ShowForEdit))
{ {
var metadata = prop as Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadata; var metadata = prop as Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadata;
object propValue = Model == null ? (prop.ModelType.IsValueType ? Activator.CreateInstance(prop.ModelType) : null) : null; object propValue = Model == null ? (prop.ModelType.IsValueType ? Activator.CreateInstance(prop.ModelType) : null) : ViewData.ModelMetadata.ModelType.GetProperty(prop.PropertyName).GetValue(ViewData.Model);
if (prop.HideSurroundingHtml) if (prop.HideSurroundingHtml)
{ {
@Html.Hidden(prop.PropertyName) @Html.Hidden(prop.PropertyName)
@ -18,25 +18,13 @@
var htmlClass = "col-sm-2 col-form-label"; var htmlClass = "col-sm-2 col-form-label";
htmlClass += isRequired ? " required" : ""; htmlClass += isRequired ? " required" : "";
<div class="form-group row"> <div class="form-group row">
@if (prop.ModelType != typeof(bool))
{
@Html.Label(prop.PropertyName, prop.GetDisplayName() + "", new { @class = htmlClass }) @Html.Label(prop.PropertyName, prop.GetDisplayName() + "", new { @class = htmlClass })
}
else
{
<div class="col-sm-2"></div>
}
<div class="col-sm-8"> <div class="col-sm-8">
@if (metadata.Attributes.Attributes.Any(o => o.GetType() == typeof(System.ComponentModel.ReadOnlyAttribute))) @if (metadata.Attributes.Attributes.Any(o => o.GetType() == typeof(System.ComponentModel.ReadOnlyAttribute)))
{ {
<div class="form-control form-control-display"> <div class="form-control form-control-display">
@Html.Hidden(prop.PropertyName) @Html.Hidden(prop.PropertyName)
@Html.Display(prop.PropertyName, prop.DataTypeName ?? prop.TemplateHint) @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> </div>
} }
else if (!string.IsNullOrEmpty(uihit) && !(uihit == "EmailAddress" || uihit == "PhoneNumber")) else if (!string.IsNullOrEmpty(uihit) && !(uihit == "EmailAddress" || uihit == "PhoneNumber"))
@ -60,15 +48,13 @@
@Html.TextBox(prop.PropertyName, null, new { @class = inputClass }) @Html.TextBox(prop.PropertyName, null, new { @class = inputClass })
} }
} }
else if (prop.ModelType == typeof(bool)) else if (prop.ModelType == typeof(bool) || prop.UnderlyingOrModelType == typeof(bool))
{ {
<div class="form-group"> <div style="padding:9px 0;">
<div class="form-check"> @Html.CheckBox(prop.PropertyName, new { style = "width:20px;height:20px;" })
@Html.CheckBox(prop.PropertyName, new { @class = "form-check-input" })
@Html.Label(prop.PropertyName, prop.DisplayName, new { @class = "form-check-label" })
</div>
</div> </div>
} }
else else
{ {
@Html.TextBox(prop.PropertyName, null, new { @class = inputClass }) @Html.TextBox(prop.PropertyName, null, new { @class = inputClass })

@ -2,6 +2,15 @@
foreach (var prop in props) foreach (var prop in props)
{ {
var templateName = prop.DataTypeName ?? prop.TemplateHint ?? (prop.ModelType == typeof(string) ? typeof(string).Name : null); var templateName = prop.DataTypeName ?? prop.TemplateHint ?? (prop.ModelType == typeof(string) ? typeof(string).Name : null);
<td style="max-width:10em;" data-ext="@templateName">@Html.Display(prop.PropertyName, templateName)</td> <td style="max-width:10em;" data-ext="@templateName">
@if (prop.UnderlyingOrModelType == typeof(bool))
{
@Html.CheckBox(prop.PropertyName, new { disabled = "disabled", style = "width:20px;height:20px;margin:2px 0;" })
}
else
{
@Html.Display(prop.PropertyName, templateName)
}
</td>
} }
} }

@ -1,7 +1,7 @@
<template> <template>
<div v-if="nullable"> <div v-if="nullable">
<select class="form-control" :id="name" :name="currentName" v-model="currentValue"> <select class="form-control" :id="name" :name="currentName" v-model="currentValue">
<option :value="null">全部</option> <option :value="null">选择</option>
<option value="true"></option> <option value="true"></option>
<option value="false"></option> <option value="false"></option>
</select> </select>

Loading…
Cancel
Save