So far it is working, but I can't seem to nail down the HTML in the correct order needed.
For every different error I need this HTML returned:
<div class="style-msg errormsg">
<div class="sb-msg">
<i class="icon-remove"></i>
Error Text
</div>
</div>
Here is the extension method:
public static string MyValidationSummary(this HtmlHelper helper, string validationMessage = "")
{
string retVal = "";
if (helper.ViewData.ModelState.IsValid)
return "";
retVal += "<div class='style-msg errormsg'><div class='sb-msg'><i class='icon-remove'></i>";
if (!String.IsNullOrEmpty(validationMessage))
retVal += helper.Encode(validationMessage);
foreach (var key in helper.ViewData.ModelState.Keys)
{
foreach (var err in helper.ViewData.ModelState[key].Errors)
retVal += helper.Encode(err.ErrorMessage);
}
retVal += "</div></div>";
return retVal.ToString();
}
}
And finally here is how I call it on the actual webpage.
@Html.Raw(Html.MyValidationSummary())
BONUS Q:
Is using HTML.Raw
safe in this instance?