asp.net mvc - How to call a server-side function from javascript in MVC? -
i doing amendments in mvc application in order disallow users open more 1 tab/ window within single session. taking reference of this article (click here) in order that. article written asp.net whereas need implement feature asp.net mvc. think should possible in mvc, however, not sure should re-write this
if(window.name != "<%=getwindowname()%>") getwindowname() function have created in controller, , returns value of "windowname" key session object. how can read value in above javascript?
you can write controller method that:
public actionresult getwindowname() { session["windowname"] = guid.newguid().tostring().replace("-", ""); return json(session["windowname"].tostring()); } then call through ajax:
$.get('@url.action("getwindowname")', function(data){ if(window.name != data) { // need here } })
Comments
Post a Comment