2017-06-01 14 views
1

ハッシュキーを使用してクエリ文字列を実行することはできません。HasKeysを使用したasp netのクエリ文字列

public partial class _Default : Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 
     HttpRequest q = Request; 
     NameValueCollection n = q.QueryString; 
     if (n.HasKeys()) 
     { 
      string k = n.GetKey(0); 
      if (k == "one") 
      { 
       string v = n.Get(0); 
      } 
     } 
    } 
} 

それはいくつかのいずれかが私を助けることができる

を動作しません:

私は、tryを持っていますか?または別の方法を教えてください。

+2

理由だけではなく、VARのV =リクエスト[ "1"]を使用しませんか? – ChrisBint

+0

私はおかげで、お試しください –

答えて

0

このお試しください:

public partial class _Default : Page { protected void Page_Load(object sender, EventArgs e) { HttpRequest q = Request; NameValueCollection n = q.QueryString; if (n.HasKeys()) { string k = n.GetKey(0); if (k == "one") { string v = n.Get(0); } if (k == "two") { string v = n.Get(0); } } } }

代替方法を:

public partial class _Default : Page { protected void Page_Load(object sender, EventArgs e) { HttpRequest q = Request; string v = q.QueryString["one"]; if (v != null) { } v = q.QueryString["two"]; if (v != null) { } } }

+0

ありがとう、あなたはとても役に立ちます –

関連する問題