asp.mvc擷取checkbox、radio、select的值

來源:互聯網
上載者:User

標籤:

記錄一下在asp.mvc中,提交表單時後台擷取checkbox、radio、select值的方法。

 1、擷取select的值

  <select name="type">      <option value="Phone">手機</option>      <option value="Pad">平板</option>      <option value="Pc">電腦</option>  </select>

   後台代碼: 

 /// <summary> /// 擷取select的值 /// </summary> /// <param name="type">類型</param> public void Test(string type) {   // 參數type和select控制項的name對應,值即為value值 }

2、擷取checkbox的值

   <input type="checkbox" name="ckRemember" />   <label for="ckRemember">記住密碼</label>

 後台代碼:

/// <summary>/// 擷取checkbox的值/// </summary>/// <param name="ckRemember">複選框的值</param>public void Test(string ckRemember){ // 參數ckRemember和checkbox控制項的name對應 // 選中值為:“on” // 未選值為:null }

 註:在傳遞checkbox的值時候,前台的html控制項不要填寫value值,不然傳遞過來的就是value值,而不是on和null

3、擷取radio的值

  <input type="radio" name="rdRemember" value="1" />男  <input type="radio" name="rdRemember" value="0" />女  

 後台代碼: 

   /// <summary>   /// 擷取redio的值   /// </summary>   /// <param name="redio">單選框的值</param>   public void Test(string redio)   {       // 參數redio為redio控制項的name對應的值,參數的值即為控制項的value值。   }

  

 

asp.mvc擷取checkbox、radio、select的值

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.