简体   繁体   English

将数据从一页传递到另一页的方法

[英]Ways to pass data from one page to another

I have scenario that I have to pass data from one page to another. 我有一种方案,我必须将数据从一页传递到另一页。 Inorder to pass that currently I am using query string as shown below. 为了传递当前,我正在使用查询字符串,如下所示。

function showNextPage(Reference) {
    window.location.href = MasterPageVars.BaseUrl + 'Home/details?Reference=' + Reference;
}

This works fine. 这很好。 But now I want to pass multiple values such as from and to date values to next page. 但是现在我想将多个值(例如,从起始日期到当前日期)传递给下一页。 what I think is by passing them using query string is not appropriate. 我认为通过使用查询字符串传递它们是不合适的。

I can get the data from database if I want. 我可以从数据库中获取数据。 But it will require separate call to database. 但这将需要单独调用数据库。 can someone point out some other methods that I can use here? 有人可以指出我可以在这里使用的其他方法吗? I knew that I can use hiddenfor, session, and cookie too. 我知道我也可以使用hiddenfor,session和cookie。 What is the best way ? 什么是最好的方法 ?

Thanks. 谢谢。

    @using (Html.BeginForm("Method", "Controller", FormMethod.Get))
        {
         <input type="datetime" name="date" placeholder="Type the date"/>
<button type="submit" class="btn btn-default">
           Submit
        </button>
}

After clicking the button, you'll pass the date you have typed just like this: http://yourhost.domain/Controller/Method?date=yy-mm-dd 单击按钮后,您将像这样输入日期: http://yourhost.domain/Controller/Method?date=yy-mm-dd


But take my advice, better use an $.ajax call, just because it is asynchronous and it won't redirect you to another page. 但是,按照我的建议,最好使用$.ajax调用,因为它是异步的,并且不会将您重定向到另一个页面。

.ajax({
            type: 'GET',
            url: '/Controller/Method/',
            data: $('input').val(),
            success: function () {
                             }
});

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

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