admin管理员组文章数量:1356908
I am doing amendments in my MVC application in order to disallow users to open more than one tab/ window within a single session. I am taking reference of this article (click here) in order to do that. This article is written for asp whereas I need to implement this feature for ASP.NET MVC. I think all this should be possible in MVC, however, I am not sure what should I do to re-write this
if(window.name != "<%=GetWindowName()%>")
GetWindowName() is a function I have created in my Controller, and it returns a value of "WindowName" key from Session object. How can I read its value in above javascript?
I am doing amendments in my MVC application in order to disallow users to open more than one tab/ window within a single session. I am taking reference of this article (click here) in order to do that. This article is written for asp whereas I need to implement this feature for ASP.NET MVC. I think all this should be possible in MVC, however, I am not sure what should I do to re-write this
if(window.name != "<%=GetWindowName()%>")
GetWindowName() is a function I have created in my Controller, and it returns a value of "WindowName" key from Session object. How can I read its value in above javascript?
Share Improve this question asked Apr 19, 2013 at 7:06 NirmanNirman 6,79321 gold badges80 silver badges147 bronze badges 1- Use Ajax !!! My apprentice ;-) – hackp0int Commented Apr 19, 2013 at 7:11
2 Answers
Reset to default 5You can write a controller method for that:
public ActionResult GetWindowName()
{
Session["WindowName"] =
Guid.NewGuid().ToString().Replace("-", "");
return Json(Session["WindowName"].ToString());
}
Then call it through ajax:
$.get('@Url.Action("GetWindowName")', function(data){
if(window.name != data) {
// do what you need to do here
}
})
You can use ajax for that (jQuery):
$.get('@Url.Action("GetWindowName")', function(result){
if(window.name != result)
//...
});
This is razor syntax...
本文标签: aspnet mvcHow to call a serverside function from javascript in MVCStack Overflow
版权声明:本文标题:asp.net mvc - How to call a server-side function from javascript in MVC? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744043753a2581143.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论