简体   繁体   中英

How to Modify Session Variable in JavaScript MVC4 Razor View engine .vbhtml

I've used this info but its not working

How to Create Session Variable in JavaScript MVC3 Razor View engine .cshtml

Any idea?

This is my SetVariable ActionResult:

Public Function SetVariable(key As String, value As String) As ActionResult
    Session(key) = value
    Return Me.Json(New With { _
        Key .success = True _
    })
End Function

This is the JS function which calls the previous function

 function Comprobacion2(s, e) { $(function () { $.post('/Home/SetVariable', { key: "cadena", value: "Nueva" }, function (data) { alert("Exito, cambio realizado " + '@Session("cadena")'); }); }); } 

I solved my issue using another function:

 function Comprobacion3(s, e) { $(function () { $.get('/Home/GetVariable', { key: "cadena" }, function (data) { alert(data); }); }); } 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM