I have a Javascript function like this:
<script>
$(document).ready(function () {
if('@TempData["Message"]' != "") {
$("#myModal").modal();
}
});
</script>
Its function is to open a modal in case the TempData comes different from null.
In the backend populo that TempData as follows:
res.Error = string.Join<string>(Environment.NewLine, errores);
TempData["Message"] = res.Error;
As you can see, for every mistake I add a new line.
When I debug the function with Chrome
I get the following error:
Uncaught SyntaxError: Invalid or unexpected token
JavaScript Output:
<script>
$(document).ready(function () {
if ('Ocurrio un error al ejecutar servicio web de Bono, para el empleado90 - NOMBRE 90 AP PAT 90 AP MAT 90
Ocurrio un error al ejecutar servicio web de Bono, para el empleado2021 - NOMBRE 2021 AP PAT 2021 AP MAT 2021
Ocurrio un error al ejecutar servicio web de Bono, para el empleado1451 - NOMBRE 1451 AP PAT 1451 AP MAT 1451
Se ejecutó el envío Bonos, sin embargo ocurrieron errores. Revisar log de errores.' != '') {
$("#myModal").modal();
}
});
</script>
But I can not find the syntax error
Now try changing the script to:
$(document).ready(function () {
if ('@Html.Raw(TempData["Message"])' != '') {
$("#myModal").modal();
}
});
But it did not work either. If the error is only one, it works correctly. So the error is when inserting a new line. Does anyone have any idea how to solve this problem? Greetings