i’m trying to show multiple error messages in view by toastr , for user register page.
I passed a list of error messages to View with TempData["errors"]
but i don’t know how to show a list of string (for errors)
I did this for a successful message and the code is as follows
register.cshtml
@if (TempData["success"] != null)
{
<script>
$(document).ready(function() {
var message = '@(TempData["success"])';
toastr.options = {
"rtl": true,
"closeButton": false,
"newestOnTop": false,
"progressBar": false,
"positionClass": "toast-top-left",
"preventDuplicates": true,
"onclick": null,
"showDuration": "300",
"hideDuration": "1000",
"timeOut": "5000",
"extendedTimeOut": "1000",
"showEasing": "swing",
"hideEasing": "linear",
"showMethod": "fadeIn",
"hideMethod": "fadeOut"
};
toastr.success(message);
});
2
Answers
Toastr supports messages with HTML tags in them. So you can put a
<br/>
tag for a line break.Try this.
Where
Errors
is a collection.Here is the screenshot
My suggestion is that:
You could turn the list to string in your controller as follow:
then replace ","with
<br/>
in your javascript codes as follow :Result:
but if you turn the list to string as follow :
controller:
Js:
Result:
If you want send Individual error message:
controller:
Js:
Result: