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.
这是很好。但是现在我想将多个值(比如from和to date)传递到下一页。我认为通过使用查询字符串传递它们是不合适的。
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. What is the best way ?
如果我想的话,我可以从数据库中获取数据。但它需要单独调用数据库。有人能指出我可以在这里使用的其他方法吗?我知道我也可以用hiddenfor, session和cookie。最好的方法是什么?
Thanks.
谢谢。
1 个解决方案
#1
1
@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?
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 () {
}
});
#1
1
@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?
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 () {
}
});