2

我想在视图中为 Html.ValidationMessageFor 定义 HTML 结构。这应该类似于 EditorTemplates。如何才能做到这一点?

4

2 回答 2

1

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.

于 2012-03-30T14:09:51.713 回答
0

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)
于 2018-11-30T22:28:27.107 回答