簡體   English   中英

ASP.NET 如何將值從表單傳遞到另一個頁面

[英]ASP.NET how to pass value from form to another page

我有一個帶有顯示我的項目列表的 url 的頁面:

https://localhost:123/AllSystems/List?systemTypeID=1

在此頁面內,我進行了搜索(我將 SearchTerm 傳遞給 list.cshtml.cs 文件):

<form method="get">
<div class="form-group">
    <div class="input-group">
        <input type="search" class="form-control" asp-for="SearchTerm" />
        <button type="button" class="btn btn-danger">
            <span class="glyphicon glyphicon-search"></span> **Search**
        </button>
    </div>
</div>
</form>

當我單擊“搜索”按鈕(在搜索表單內)時,我會轉到 url: https://localhost:123/AllSystems/List?SearchTerm=nba

那很好,但我想將 systemTypeID=1 傳遞給最后一個 url ( https://localhost:123/AllSystems/List?systemTypeID=1 )。 我怎么做?

我希望結果是這樣的: https://localhost:123/AllSystems/List?systemTypeID=1&SearchTerm=nba

謝謝

您可以將多個動態值傳遞給 QueryString 如下您可以設置Value1Value2並將該值傳遞給您的查詢字符串,如下所示

string value1="1";
string value2="nba";


Response.Redirect("https://localhost:123/AllSystems/List?systemTypeID"+value1+"&SearchTerm="+value2);

在第二頁中,您可以訪問該值,例如

string typeid= Request.QueryString["systemTypeID"];
string searchvalue = Request.QueryString["SearchTerm"];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM