简体   繁体   English

如何将值从一个页面javascript传递到另一页面javascript

[英]how to pass the value one page javascript to another page javascript

I need to pass the value one page javascript to another page javascript particular functionality . 我需要将值一页javascript传递给另一页javascript特定功能。 I ma using the mvc function the two pages are different controller cshtml pages. 我可能使用mvc函数,这两个页面是不同的控制器cshtml页面。 How to pass the value one cshtml to another one cshtml. 如何将一个cshtml的值传递给另一个cshtml。 I try this code but not trigger. 我尝试此代码,但不触发。 Please forward your knowledge 请转发您的知识

view1:

 b.on('click', function () {
          document.location.href = +'/view2.cshtml?Id=' + sData; // notes:
    });

view2:

 var data = $_POST['Id'];
    function work(data) {
    // my code
    }

notes: 笔记:

I dont know how to mention the particular view2. 我不知道该怎么说。 Because i have lot of controller every controller have the same view2 name. 因为我有很多控制器,所以每个控制器都有相同的view2名称。 This code goes to the my current controller view 2 该代码转到我当前的控制器视图2

Try like this: 尝试这样:

b.on('click', function () {
      document.location.href = +'/controllerName/View2?Id=' + sData; // notes:
});

On your controller you should be accessing the querystring parameter. 在您的控制器上,您应该访问querystring参数。

public ActionResult View2(int Id)
{
    ViewData["ID"]=Id; //you can store the Id in ViewData or ViewBag
    return View();
}

Now in your view2.cshtml file, display the ViewDate that you have stored. 现在,在您的view2.cshtml文件中,显示您已存储的ViewDate。

 @ViewData["ID"]

Hope it helps 希望能帮助到你

jQuery Cookie might help: https://github.com/carhartl/jquery-cookie jQuery Cookie可能会有所帮助: https : //github.com/carhartl/jquery-cookie

view 1, set data: 查看1,设置数据:

$.cookie('my_cookie', 'sData');

view 2, get data: 查看2,获取数据:

$.cookie('my_cookie');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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