0

I am trying to validate view model overriding ValidationAttribute.

  1. Validation is working fine but when I try to display it using below

    @Html.ValidationSummary("ViewModel")

    Output: ViewModel *Custom Error message**

    How to remove "ViewModel" from it.

  2. "IsValid" method of "ValidationAttribute" class is getting called twice

4

2 に答える 2

0

試す

@Html.ValidationSummary(true);
于 2012-09-15T03:44:19.340 に答える
0

そもそもカスタムモデルの検証エラーメッセージをどのように書くのですか?

プロパティ関連の場合は、次のように追加する必要があります。

ModelState.AddModelError("PropertyName", "Custom Error message");

次に、ビューで、次の方法でメッセージを表示できます。

@Html.ValidationMessageFor(m=>m.PropertyName)
于 2012-09-16T07:48:52.463 に答える