Should the validation summary appear in the warning window?

I have a view that contains a form. The controls have annotations in my model. I want to

@Html.ValidationSummary(); 

will appear in the warning message box.

Is there any way. I am new to mvc, so please clarify the answer.

Thanks in advance!

+4
source share
1 answer

I do not have my computer with me, so I can not provide an example, but @Html.ValidationSummary() returns an unordered list of errors. (see http://msdn.microsoft.com/en-us/library/dd460343(v=vs.108).aspx )

You can check if @Html.ValidationSummary() value in JavaScript, and then use jQuery to pull out the text values ​​of the <li> elements and put them in a warning.

Try this, I have not tested it yet, but this should be a guide:

 <script> var validationSummary = '@Html.ValidationSummary()'; var alerttext = ''; if (validationSummary !== '') { $(validationSummary) .find('li').each( function() { alerttext = alerttext + $(this).text() + '\n'; }); alert(alerttext); } </script> 
+3
source

All Articles