ASP.NET MVC - Replace label with validation error message?
I'd lik开发者_开发问答e to highlight field names instead of showing a separate error message when there is a validation error.
Is there any convenient way of doing this other than checking the ModelState Errors collection and wrapping each .LabelFor()
in an if
?
Also, I'd like to format labels as either bold, or add an asterisk if the model metadata has a [Required]
attribute.
You'll need use a custom Object.ascx file by creating either /Shared/DisplayTemplates/Object.ascx or /Shared/EditorTemplates/Object.ascx
I can't answer any better than this guide at Brad Wilson's blog: http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-4-custom-object-templates.html
精彩评论