Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在其他部件中对视图模型进行lcoated时,不尊重DisplayAttribute_C#_Asp.net Mvc_Asp.net Core - Fatal编程技术网

C# 在其他部件中对视图模型进行lcoated时,不尊重DisplayAttribute

C# 在其他部件中对视图模型进行lcoated时,不尊重DisplayAttribute,c#,asp.net-mvc,asp.net-core,C#,Asp.net Mvc,Asp.net Core,我只将模型类移动到了其他程序集,所有其他内容都非常基本(我刚刚移动到了区域帐户注册) 公共类RegisterViewModel { [必需] [电邮地址] [显示(Name=“电子邮件”)] 公共字符串电子邮件{get;set;} [必需] [StringLength(100,ErrorMessage={0}必须至少为{2}个字符,最大长度为{1}个字符。”,最小长度=6)] [数据类型(数据类型.密码)] [显示(Name=“密码”)] 公共字符串密码{get;set;} [数据类型(数据类型

我只将模型类移动到了其他程序集,所有其他内容都非常基本(我刚刚移动到了区域帐户注册)

公共类RegisterViewModel
{
[必需]
[电邮地址]
[显示(Name=“电子邮件”)]
公共字符串电子邮件{get;set;}
[必需]
[StringLength(100,ErrorMessage={0}必须至少为{2}个字符,最大长度为{1}个字符。”,最小长度=6)]
[数据类型(数据类型.密码)]
[显示(Name=“密码”)]
公共字符串密码{get;set;}
[数据类型(数据类型.密码)]
[显示(Name=“确认密码”)]
[比较(“密码”,ErrorMessage=“密码和确认密码不匹配。”)]
公共字符串ConfirmPassword{get;set;}
}
@模型NewAssembly.Models.AccountViewModels.RegisterViewModel
@{
Layout=“~/Views/Shared/_Layout.cshtml”;
ViewData[“标题”]=“寄存器”;
}
@ViewData[“标题”]。
创建一个新帐户。

登记 @节脚本{ @{wait Html.RenderPartialAsync(“_validationScript”);} }
之后,我在输入控件附近看不到显示名称,
如何在ASP.NET Core上修复它?

轻微更正,不是答案,但您已将ViewModels移动到另一个程序集。你把它们放在模型下面,这确实很奇怪。确保(检查并添加到你的帖子中)主项目也引用了注释程序集。好的,只是做了一点检查。它在我的电脑上运行良好。请不要互换使用ASP.NET核心和.NET核心!!!NET核心是Rest Api/MVC webstack,.NET核心是运行时。你的问题无论如何都与runtime@HenkHolterman我相信我在TagHelper上遇到了一些问题,因为某种原因,没有生成正确的HTML输出
  public class RegisterViewModel
    {
        [Required]
        [EmailAddress]
        [Display(Name = "Email")]
        public string Email { get; set; }

        [Required]
        [StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)]
        [DataType(DataType.Password)]
        [Display(Name = "Password")]
        public string Password { get; set; }

        [DataType(DataType.Password)]
        [Display(Name = "Confirm password")]
        [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
        public string ConfirmPassword { get; set; }
    }


@model NewAssembly.Models.AccountViewModels.RegisterViewModel
@{
    Layout = "~/Views/Shared/_Layout.cshtml";
    ViewData["Title"] = "Register";
}

<h2>@ViewData["Title"].</h2>

<form  asp-controller="Account" asp-action="Register" asp-route-returnurl="@ViewData["ReturnUrl"]" method="post" class="form-horizontal">
    <h4>Create a new account.</h4>
    <hr />
    <div asp-validation-summary="All" class="text-danger"></div>
    <div class="form-group">
        <label asp-for="Email" class="col-md-2 control-label"></label>
        <div class="col-md-10">
            <input asp-for="Email" class="form-control" />
            <span asp-validation-for="Email" class="text-danger"></span>
        </div>
    </div>
    <div class="form-group">
        <label asp-for="Password" class="col-md-2 control-label"></label>
        <div class="col-md-10">
            <input asp-for="Password" class="form-control" />
            <span asp-validation-for="Password" class="text-danger"></span>
        </div>
    </div>
    <div class="form-group">
        <label asp-for="ConfirmPassword" class="col-md-2 control-label"></label>
        <div class="col-md-10">
            <input asp-for="ConfirmPassword" class="form-control" />
            <span asp-validation-for="ConfirmPassword" class="text-danger"></span>
        </div>
    </div>
    <div class="form-group">
        <div class="col-md-offset-2 col-md-10">
            <button type="submit" class="btn btn-default">Register</button>
        </div>
    </div>
</form>

@section Scripts {
    @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
}