I want to add a ModelState error, like so:
ModelState.AddModelError("", "Some message, <a href="/controller/action">click here</a>)
However, the link doesn't get encoded, and so is displayed like text. I tried using
<%= Html.ValidationSummary(true, "Some message")
instead of
<%: Html.ValidationSummary(true, "Some message")
But no luck.
Anyone have any idea how to get this working?
Cheers
<div class="validation-summary-errors">
<ul>
<% foreach(var error in ViewData.ModelState.Where(s => s.Value.Errors.Count!=0).SelectMany(s => s.Value.Errors)) { %>
<li><%= error.ErrorMessage %></li>
<% } %>
</ul>
</div>
or in razor:
<div class="validation-summary-errors">
<ul>
@foreach(var error in ViewData.ModelState.Where(s => s.Value.Errors.Count!=0).SelectMany(s => s.Value.Errors)) {
<li>@Html.Raw(error.ErrorMessage)</li>
}
</ul>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With