开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜