You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
4.4 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

@using System.Reflection
@using System.ComponentModel
@using Microsoft.AspNetCore.Mvc.Controllers
@using Infrastructure.Web.Mvc
@{
var scope = (Url.ActionContext.ActionDescriptor as ControllerActionDescriptor).ControllerTypeInfo.GetCustomAttribute<ControllerScopeAttribute>()?.Scope;
var controller = this.ViewContext.RouteData.Values["controller"].ToString();
var action = this.ViewContext.RouteData.Values["action"].ToString();
var url = HtmlAction ?? (ViewData.Keys.Any(o => o.ToLower() == "returnurl") ? Url.Action(null, null, new { ReturnUrl = ViewData["ReturnUrl"] }) : Url.Action(null, null));
var props = ViewData.ModelMetadata.Properties.Where(pm => pm.ShowForEdit);
}
<div class="card card-info">
<form action="@url" method="post" class="form-horizontal">
<div class="card-body">
@Html.AntiForgeryToken()
<div class="form-group row">
<div class="col-sm-2 col-form-label"></div>
@Html.ValidationSummary(true, "错误:", new { @class = "text-danger col-sm-6" }, "div")
<div class="col-sm-4"></div>
</div>
@foreach (var prop in props)
{
var metadata = prop as Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadata;
var isReadOnly = metadata.Attributes.Attributes.Any(o => o.GetType() == typeof(ReadOnlyAttribute));
if (action == "Edit")
{
isReadOnly = isReadOnly || metadata.Attributes.Attributes.Any(o => o.GetType() == typeof(ReadOnlyForEditAttribute));
}
if (scope != null && scope == ControllerScopeType.Organ && prop.PropertyName == "OrganId")
{
@Html.Hidden(prop.PropertyName)
continue;
}
if (prop.HideSurroundingHtml)
{
@Html.Hidden(prop.PropertyName)
continue;
}
var uihit = prop.DataTypeName ?? prop.TemplateHint;
<div class="form-group row @prop.ModelType.Name @uihit">
@Html.Label(prop.PropertyName, prop.GetDisplayName() + "", new { @class = "col-sm-2 col-form-label", style = "text-align: right;overflow:hidden;" })
<div class="col-sm-6">
@if (isReadOnly)
{
<div class="form-control" style="border-color:transparent;height:auto;">
@Html.Hidden(prop.PropertyName)
@Html.Display(prop.PropertyName, uihit)
</div>
}
else
{
@Html.Editor(prop.PropertyName, uihit)
}
@Html.ValidationMessage(prop.PropertyName, new { @class = "text-danger" })
</div>
<div class="col-sm-4">
@{
if (metadata != null)
{
var attr = metadata.Attributes.Attributes.OfType<DescriptionAttribute>().FirstOrDefault() as DescriptionAttribute;
if (attr != null && attr.Description != null)
{
<span class="form-control form-control-display">@attr.Description</span>
}
}
}
</div>
</div>
}
<div class="form-group row">
<div class="col-sm-2"> </div>
<div class="col-sm-8">
@if (!DisableBackUrl && string.IsNullOrEmpty(BackUrl))
{
BackUrl = Url.Action("Index", null);
<a class="btn btn-default" href="@BackUrl">
返回
</a>
}
<button class="btn btn-primary" type="submit">
确定
</button>
@if (controller == "Account" && action == "Login")
{
<a class="ForgotPassword" href="@Url.Action("ForgotPassword")">忘记密码?</a>
}
</div>
</div>
</div>
</form>
</div>