0

I have the following string in french languages which contains single quotes between the characters and words. This message I want to show in alert.

string Mlocal = "Ce porduit n'a pas encore été livré.";


TempData["msg_Vide"] = "<script>alert('" + Mlocal + "');</script>";

the alert not showing

i use escape "\'" and "&sbquo;" and "&#8218;" and "&#39;" but not working

passing string value is ok, but passing alert message with the special characters no ok

1

1 Answer 1

1

Just pass the string to you view and let your view do the rest (and of course escape your single quote:

public IActionResult Index()
{
    TempData["msg_Vide"] = "Ce porduit n\\'a pas encore été livré.";
    return View();
}

View:

@if(TempData["msg_Vide"] != null) { 
    <script>
        alert('@Html.Raw(TempData["msg_Vide"])')
    </script>
}

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

i use in controller if (Mlocal != null) { TempData["msg_Vide"] = "<script>alert('" + Mlocal + "');</script>"; ViewBag.msg_Vide = Mlocal; } else { TempData["msg_Vide"] = ""; } and in view : @Html.Raw(TempData["msg_Vide"]) thank you is working now

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.