0

Although there are several same questions, I'm very curious regarding this specific case.

jQuery(document).ready(function () {
  if ($('#msg').val() != '' && $('#msgSuccess').val() == 'true') {
    var msg = $('#msg').val();
    var t = $('#msg').val().toString();
    toastr.success("@_localizer[t]");
  }
});

variable t has some message which represents the key for my localization file. I have issue to pass that variable (string) to my mvc _localizer. Where I go wrong with this?

If I add simple console.log(t) it works. So Im guessing that is the localizer is a problem.

I'm using @inject IViewLocalizer _localizer from AspNetCore.Mvc.Localization

mplungjan
  • 169,008
  • 28
  • 173
  • 236
Stefan0309
  • 1,602
  • 5
  • 23
  • 61
  • 3
    Start here: [What is the difference between client-side and server-side programming?](https://stackoverflow.com/q/13840429) – VLAZ Apr 06 '21 at 09:21
  • So, Icant pass the variable? I know that i can pass pure string for example `toastr.success("@_localizer["SuccessMessage"]");` – Stefan0309 Apr 06 '21 at 09:25
  • 2
    If `@_localizer` is backend code? You can't, as the back-end will have already finished running – evolutionxbox Apr 06 '21 at 09:26
  • @Stefan0309 yes, you can pass a string, *if you have the string on the server*. However, `t` completely client-side, so you cannot expect to get the value of `t` *after* when that code runs on a completely different machine. – VLAZ Apr 06 '21 at 09:30
  • @Stefan0309 if you want to dynamic js should start new request ajax, websocket etc. or you can place all variables to javascript at start – Abdullah Apr 06 '21 at 09:30

0 Answers0