asp.net-mvc-3 – 在ASP.NET MVC 3中应用数据注释时,如何使用提
发布时间:2020-12-15 23:06:43 所属栏目:asp.Net 来源:网络整理
导读:我有一个带有属性的视图模型,如下所示: [Display(Name = "Some Property",Description = "This is description",Prompt = "This is prompt")] [Required(ErrorMessage = RequiredFieldMessage)] public string SomeProperty { get; set; } 但这似乎没有在视
我有一个带有属性的视图模型,如下所示:
[Display(Name = "Some Property",Description = "This is description",Prompt = "This is prompt")] [Required(ErrorMessage = RequiredFieldMessage)] public string SomeProperty { get; set; } 但这似乎没有在视图中呈现任何额外的内容.你需要做一些额外的工作吗? <div class="editor-label"> @Html.LabelFor(model => model.SomeProperty ) </div> <div class="editor-field"> @Html.TextAreaFor(model => model.SomeProperty,5,80,null) @Html.ValidationMessageFor(model => model.SomeProperty ) </div> 解决方法
并非所有内置的EditorTemplates都利用了所有的DataAnnotations,但是当你编写自己的EditorTemplates时,它们就可以利用它们.
除非您正在使用DisplayForModel或EditorForModel来显示模型上所有属性的多个编辑器,否则排序并不真正适用,它可以适当地对编辑器进行排序. 如果您想利用Description和Prompt元数据,您可以编写自己的String EditorTemplate: @model string @Html.TextBox("",ViewData.TemplateInfo.FormattedModelValue,new { @title = ViewData.ModelMetadata.Description,@placeholder = ViewData.ModelMetadata.Watermark}) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- asp.net-mvc-3 – 是否可以设置TextBoxFor生成的
- asp.net-mvc – MVC中的绑定集合
- asp.net – 如何在EF DbContext和AspNet Members
- asp.net – 将单元测试慢慢集成到项目中的步骤
- DevExpress ASP.NET示例资源最全分享!(一)
- asp.net – 向GridView添加默认排序箭头
- .NET Core技术研究-主机Host ASP.NET
- 处理asp:ScriptManager时,mscorlib.dll中的asp.
- asp.net-mvc-3 – 是否可以强制使用DataType作为
- asp.net-mvc – 将DropDownListFor绑定到字典
热点阅读