I want to configure html output for ValidationSummary in ASP.NET MVC 2
of
<div class="validation-summary-errors"> <span>Oops! validation was failed because:</span> <ul> <li>The Title field is required.</li> <li>The Body field is required.</li> </ul> </div>
to
<div class="validation-error"> <p>Oops! validation was failed because:</p> <ul> <li>The Title field is required.</li> <li>The Body field is required.</li> </ul> </div>
Is there any new way in asp.net MVC 2 to solve this problem?
There seems to be no way to do this with templates, which is pretty bad. If you look at the code for this particular helper method, you will see that the HTML is baked in the method itself:
public static string ValidationSummary(this HtmlHelper htmlHelper, string message, IDictionary<string, object> htmlAttributes) { // Nothing to do if there aren't any errors if (htmlHelper.ViewData.ModelState.IsValid) { return null; } string messageSpan; if (!String.IsNullOrEmpty(message)) { TagBuilder spanTag = new TagBuilder("span"); spanTag.MergeAttributes(htmlAttributes); spanTag.MergeAttribute("class", HtmlHelper.ValidationSummaryCssClassName); spanTag.SetInnerText(message); messageSpan = spanTag.ToString(TagRenderMode.Normal) + Environment.NewLine; } else { messageSpan = null; } StringBuilder htmlSummary = new StringBuilder(); TagBuilder unorderedList = new TagBuilder("ul"); unorderedList.MergeAttributes(htmlAttributes); unorderedList.MergeAttribute("class", HtmlHelper.ValidationSummaryCssClassName); foreach (ModelState modelState in htmlHelper.ViewData.ModelState.Values) { foreach (ModelError modelError in modelState.Errors) { string errorText = GetUserErrorMessageOrDefault(htmlHelper.ViewContext.HttpContext, modelError, null /* modelState */); if (!String.IsNullOrEmpty(errorText)) { TagBuilder listItem = new TagBuilder("li"); listItem.SetInnerText(errorText); htmlSummary.AppendLine(listItem.ToString(TagRenderMode.Normal)); } } } }
The good news is that with open source MVC, you can go and grab the source from the CodePlex repository and configure it in some way how.
Alternatively, you can reference this range via CSS and set it as p.
This is a way to link to it - you will need to adjust it accordingly:
.validation-summary-errors > span { margin: 0px; }
Source: https://habr.com/ru/post/1310933/More articles:Do I need to download binary files to test in-app purchases? - iphonein HTML loaded by Webview Broken in Sense - androidCan I use the TFS object model to interact with TFS through F #? - tfsErlang: Interaction with Xalan: port driver or nif? - erlangPause download for Apache - phpSQL different joins have no meaning for the result - sqlhow to represent an integer array using java.util.BitSet? - javaModification of a subscription Paypal - subscriptionasp.net mvc and portal as functionality - model-view-controllerA faster way to compare two sets of points in an N-dimensional space? - mathAll Articles