2017-12-12 10 views
2

私は、ページからページに変数を渡している問題があります。ここでは、はいまたはいいえの2つのオプションを選択できるドロップダウンメニューがあります。 Chooseのデフォルトを使用します。ここで私は私がDefCon5が正確として読んでされていないため、if文が失敗したことを気づい.NetドロップダウンメニューC#

string yes = Request.Params["Yes"]; 
string no = Request.Params["No"]; 
var DefCon5 = Request["DefCon5"]; 
string message = Request.Params["message"]; 
string redirURL = ""; 


if (DefCon5 == "yes") 
{ 
    Response.Write(@message); 
    Response.Write(@Defcon); 
    redirURL = "/somepage"; 
} 
else 
{ 

    redirURL = "/DefCon5"; 
} 

(テスト目的のために、私ははいを選択した)これら二つのオプションの1取る

<form method="post" id="Form" action="/admin/DefCon5"> 
    <table align="center" style="width: 200px; height: 140px;"> 
     <tr> 
      <td colspan="5"><img src="/images/logo.png"><br>&nbsp;</td> 
     </tr> 
    </table> 
    <div align="center"> 
     <select id = "DefCon5" align="center" valign="top" name="DefCon5"> 
      <option value="Choose">Choose..</option> 
      <option value="Yes">Yes</option> 
      <option value="No">No</option> 
     </select> 
     <br /> 
     &nbsp &nbsp &nbsp &nbsp &nbsp 
     <textarea align="Center" name="message" value="message" rows="4" cols="40">Please enter a brief message before engaging DefCon5</textarea> 
     <br /> 
     <input type="submit"> 
     </div> 

はい。私は前のページの変数と最後にリテラル文字列 "Yes"を試しました。私は変更を加えずにいくつかのリクエストを試しました。私は間違ってはい/いいえを渡すかもしれないと信じていますが、なぜこれが当てはまるのかは不明です。

+1

デバッガでそれを見ている必要があり、私はRequest.Params(「はい」)バックとしてnullまたは空の来ることを期待するだろうと思いますDefCon5、それはYesまたはNoになる値ですが、私は "if(DefCon5 ==" Yes ")"と一致すると予想していました。 – SoronelHaetir

+0

これはまさにそれだった。 My Ifステートメントは小文字でした。ご協力ありがとうございました。 –

答えて

0

私は、パラメータ、あなたのコントローラのコードでは、このような変化

public ActionResult DefCon5(string DefCon5,string message) 
     { 
      //string yes = Request.Params["Yes"]; 
      //string no = Request.Params["No"]; 
      //var DefCon5 = Request["DefCon5"]; 
      //string message = Request.Params["message"]; 
      string redirURL = ""; 


      if (DefCon5.ToLower() == "yes") 
      { 
       Response.Write(@message); 
       //Response.Write(@Defcon); 
       redirURL = "/somepage"; 
      } 
      else 
      { 

       redirURL = "/DefCon5"; 
      } 

      // your code here 

      return View(); 
     } 
+0

ありがとう!私のifステートメントは「はい」と読んでいたが、中にあったのは「はい」だった –

関連する問題