如何在C#中向当前URL添加一个参数 [英] How to add one parameter to current url in c#

查看:224
本文介绍了如何在C#中向当前URL添加一个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个链接

 <li class="active">
  <a href="<%#CurrentSearchUrl%>"><span>Current search Page
 </span></a> 

  <li><a href="<%#CurrentSearchUrlParam%>"><span>Add param </span>
      </a> 

在Page_Load中

in the Page_Load

    CurrentSearchUrl = Request.Url.AbsoluteUri;
    CurrentSearchUrlParam = Request.Url+"&discount=1";

已添加参数,但网址不正确我当前的网址是

param is added but url is not correct my current url is

http://localhost:1067/search/default.aspx?q=test

我想添加一个参数,期望的结果应该是

I want to add one parameter, the desired result should be

http://localhost:1067/search/default.aspx?q=test&discount=1

预先感谢

推荐答案

有很多方法可以做到这一点.例如:

There are many way to do that. For example :

您的HTML:

<li class="active">
  <a href="" runat="server" ID="Link1"><span>Current search Page
 </span></a> 

  <li><a href="" runat="server" ID="Link2"><span>Add param </span>
      </a> 

在Page_Load中:

In the Page_Load :

Link1.HRef = HttpContext.Current.Request.Url.ToString();
Link2.HRef = HttpContext.Current.Request.Url.ToString()+"&discount=1";

这篇关于如何在C#中向当前URL添加一个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆