Reputation: 21
I want to define HTML structure for Html.ValidationMessageFor in a View. This should be similar to EditorTemplates. How can this be done?
Upvotes: 2
Views: 1148
Reputation: 21
The view can use the custom HtmlHelper method by adding a reference to the method's namespace.
My view, after using @Darin Dimitrov's guidance, looks similar to the following code:
@model Project.Models.MyModel
@using Project.Helper;
...
@Html.ValidationMessageFor_ThatYouMade(model => model.PropertyBeingValidated)
Upvotes: 0
Reputation: 1039538
How can this be done?
It can't be done. You will have to write a custom ValidationMessageFor helper. The generated HTML is not extensible and is hardcoded in the built-in helper. You may download the ASP.NET MVC 3 source code and see how the default helper is implemented. This could be used as a starting point for writing your custom helper that will generate the desired markup.
Upvotes: 1