-1

Please help,

My javascript code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="~/Scripts/jquery-1.9.1.js"></script>

<script type="text/javascript">
    $(function() {
        var url = "../Account/DeconnecterUtilisateur";
        var statutLogin = @HttpContext.Current.User.Identity.Name;
        $.getJSON(url, { usr: id }, function (data) {
            console.log(data);
        })
    });
</script>

is throwing this error message

(index):87 Uncaught ReferenceError: patrice is not defined

And I can not get arround it.

My aim is to call within my account controller a method that will log off the user when ever that specifc view(that cobtains the script) is loaded.

Patrice
  • 115
  • 1
  • 1
  • 14
  • 1
    In some place of your code as if not present here, reference of `patrice` is not found – BrTkCa Oct 19 '16 at 00:29
  • Is it possible the name you send is patrice? maybe using this will help: var statutLogin = '@HttpContext.Current.User.Identity.Name'; – Dror Oct 19 '16 at 00:37
  • Possible duplicate of [How to get the current login user name in my Script file inside my asp.net mvc](http://stackoverflow.com/questions/12820172/how-to-get-the-current-login-user-name-in-my-script-file-inside-my-asp-net-mvc) – Dror Oct 19 '16 at 00:38
  • The quotes did settle the issue. Thanks – Patrice Oct 19 '16 at 15:14

1 Answers1

0

Rewrite to this:

var statutLogin = '@HttpContext.Current.User.Identity.Name';

Notice you need the apostrophes above since c# is generating js code before the script runs.

Mattias Åslund
  • 3,877
  • 2
  • 18
  • 17