首页 新闻 搜索 专区 学院

这个是.NetCore 2.2的bug吗?

0
悬赏园豆:5 [已解决问题] 解决于 2019-06-03 21:47
/// <summary>
        /// 页面标题
        /// </summary>
        [Display(Name = "页面标题")]
        [Required(ErrorMessage = "{0}不能为空")]
        [StringLength(20, ErrorMessage = "{0}长度在{2}~{1}个字符之间", MinimumLength = 1)]
        [DisplayFormat(ConvertEmptyStringToNull = false)]
        public string title { get; set; }
        /// <summary>
        /// 页面索引
        /// </summary>
        [Display(Name = "页面索引")]
        [Required(ErrorMessage ="{0}不能为空")]
        [StringLength(20,ErrorMessage ="{0}长度在{2}~{1}个字符之间",MinimumLength =1)]
        [DisplayFormat(ConvertEmptyStringToNull = false)]
        public string titleindex { get; set; }

为什么title上的Required和StringLength属性不起作用?而Display又起作用?

模板代码:

<div class="form-group">
                                        @Html.LabelFor(model => model.title, htmlAttributes: new { @class = "control-label col-md-2" })
                                        <div class="col-md-10">
                                            @Html.EditorFor(model => model.title, new { htmlAttributes = new { @class = "form-control" } })
                                            @Html.ValidationMessageFor(model => model.title, "", new { @class = "text-danger" })
                                        </div>
                                    </div>
                                    
                                    <div class="form-group">
                                        @Html.LabelFor(model => model.titleindex, htmlAttributes: new { @class = "control-label col-md-2" })
                                        <div class="col-md-10">
                                            @Html.EditorFor(model => model.titleindex, new { htmlAttributes = new { @class = "form-control" } })
                                            @Html.ValidationMessageFor(model => model.titleindex, "", new { @class = "text-danger" })
                                        </div>
                                    </div>

生成的代码:

<div class="form-group">
                                        <label class="control-label col-md-2" for="title">页面标题</label>
                                        <div class="col-md-10">
                                            <input class="form-control text-box single-line" id="title" name="title" type="text" value="">
                                            <span class="field-validation-valid text-danger" data-valmsg-for="title" data-valmsg-replace="true"></span>
                                        </div>
                                    </div>
<div class="form-group">
                                        <label class="control-label col-md-2" for="titleindex">页面索引</label>
                                        <div class="col-md-10">
                                            <input class="form-control text-box single-line input-validation-error" data-val="true" data-val-length="页面索引长度在1~20个字符之间" data-val-length-max="20" data-val-length-min="1" data-val-required="页面索引不能为空" id="titleindex" maxlength="20" name="titleindex" type="text" value="" aria-describedby="titleindex-error" aria-invalid="true">
                                            <span class="text-danger field-validation-error" data-valmsg-for="titleindex" data-valmsg-replace="true"><span id="titleindex-error" class="">页面索引不能为空</span></span>
                                        </div>
                                    </div>

看生成的二段代码,title中的属性没有生效。

经过测试,title,Title只要是这个关键字,都会不起作用,不论大小写。

不知你们有没有碰到过?环境:vs2019+.netcore 2.2

DZCMS的主页 DZCMS | 初学一级 | 园豆:5
提问于:2019-06-02 19:17
< >
分享
最佳答案
0

之前有人在博问中问过类似问题,详见 https://q.cnblogs.com/q/112959/

收获园豆:5
dudu | 高人七级 |园豆:36087 | 2019-06-02 20:17
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册