4

I want to show the validation summary as HTML format, for example.

Code behind (controller):

ModelState.AddModelError("", "Account not confirmed<br />Click <a href='#'>here</a> to resend the email confirmation");

Razor View:

@Html.ValidationSummary(true, "", new { @class = "text-danger" });

An the rendered HTML is like:

Account not confirmed<br />Click <a href='#'>here</a> to resend the email confirmation

I mean, the html message is shown as it, but I want it to show with HTML tags.

GEOCHET
  • 21,119
  • 15
  • 74
  • 98
Edgwin
  • 61
  • 1
  • 1
  • 7
  • http://stackoverflow.com/questions/5005966/mvc-3-display-html-inside-a-validationsummary – AaronLS May 19 '16 at 22:47
  • 1
    You cannot. `@Html.ValidationSummary()` encodes the value. You need to create your own html (and validation messages are for displaying errors, not for displaying instructions) –  May 19 '16 at 23:24

2 Answers2

3

You can create your own ValidationSummary, Create a partial and named it _MyValidationSummary.cshtml

@model ModelStateDictionary
@if(!Model.IsValid)
{
    <div class="validation-summary-errors">
        <p>
            "Account not confirmed<br />
            Click <a href='#'>here</a> to resend the email confirmation"
        </p>
        <ul>
            //Errors
        </ul>
    </div>
}

Refer to it:

@Html.Partial("_MyValidationSummary", ViewData.ModelState);
AliD32
  • 111
  • 5
2

Thanks everyone for your time ... I found what I need:

Render HTML in a Validation Message in ASP.NET MVC

Edgwin
  • 61
  • 1
  • 1
  • 7