2014-02-23 25 views
0

當我將選擇複選框,並將點擊選擇按鈕如何我可以得到這個值的文本框的值。這裏checkbox id = chk和textbox id = OrderNo。請幫我....我有下面的東西....如何獲取mvc中的複選框值?

$("#OrderNo").blur(function() { 
    $.get('/Ordering/OrderList/', function(data) { 
     $('#orlist').html(data); 
    }); 
    $('#orlist').dialog({ 
     width: 500, 
     height: 350, 
     open: true, 
     title: 'Select Order', 
     buttons: { 
      Select: function() { 
       if (("#chk") == 'checked') { 
        var por = ("#porderno").val(); 
        por = ("#OrderNo"); 
       } 
      }, 
      Cancel: function() { 
       $('#orlist').dialog('close'); 
       $('#orlist').empty(); 
      } 
     } 
    }); 

局部視圖頁面

@model IEnumerable<testcon.OrderM> 
<table> 
    <tr> 
     <th> 
      @Html.DisplayNameFor(model => model.OdrId) 
     </th> 
     <th> 
      @Html.DisplayNameFor(model => model.OrderNo) 
     </th> 
     <th> 
      @Html.DisplayNameFor(model => model.CId) 
     </th> 
    </tr> 

@foreach (var item in Model) { 
    <tr> 
     <td> 
      @Html.CheckBox("OdrId", new { @id="chk"}) 
     </td> 
     <td class="left"> 
      @Html.DisplayFor(modelItem => item.OrderNo, new { @id="porderno"}) 
     </td> 
     <td class="left"> 
      @Html.DisplayFor(modelItem => item.CId) 
     </td> 

    </tr> 
} 

</table> 

和我的創建視圖頁面

@model testcon.DeliveryInfo 

@{ 
    ViewBag.Title = "Create"; 
} 

<h2>Create</h2> 

@using (Html.BeginForm()) { 
    @Html.ValidationSummary(true) 

    <fieldset> 
     <legend>DeliveryInfo</legend> 

     @*<div class="editor-label"> 
      @Html.LabelFor(model => model.DId) 
     </div>*@ 
     <div class="editor-field"> 
      Delivery Id : @Html.EditorFor(model => model.DId) 
      @Html.ValidationMessageFor(model => model.DId) 
     </div> 

     @*<div class="editor-label"> 
      @Html.LabelFor(model => model.OrderNo) 
     </div>*@ 
     <div class="editor-field"> 
      Order No :@Html.EditorFor(model => model.OrderNo) 
      @Html.ValidationMessageFor(model => model.OrderNo) 
      @*<a href="#" onclick="javascript:getOrderList()">Show Order</a>*@ 
     </div> 

     @* <div class="editor-label"> 
      @Html.LabelFor(model => model.DDate) 
     </div>*@ 
     <div class="editor-field"> 
      Delivery Date : @Html.EditorFor(model => model.DDate) 
      @Html.ValidationMessageFor(model => model.DDate) 
     </div> 

     @*<div class="editor-label"> 
      @Html.LabelFor(model => model.DQuantity) 
     </div>*@ 
     <div class="editor-field"> 
      Delivery Quantity: @Html.EditorFor(model => model.DQuantity) 
      @Html.ValidationMessageFor(model => model.DQuantity) 
     </div> 

     @*<div class="editor-label"> 
      @Html.LabelFor(model => model.DAmount) 
     </div>*@ 
     <div class="editor-field"> 
      Delivery Amount : @Html.EditorFor(model => model.DAmount) 
      @Html.ValidationMessageFor(model => model.DAmount) 
     </div> 
     <div id="orlist" > 
     </div> 

     <p> 
      <input type="submit" value="Create" /> 
     </p> 
    </fieldset> 
} 

<div> 
    @Html.ActionLink("Back to List", "Index") 
</div> 
+0

你能證明你的HTML代碼 – Akhlesh

+1

這(「#chk」),必須爲$ (「#chk」)和這個var por =(「#porderno」)。val();應該是var por =(「#porderno」)。val($((「#chk」)).val());也刪除這一行por =(「#OrderNo」);我不明白爲什麼。 – rgdesign

+0

@akhlesh我已更新我的html代碼 – MNAH

回答

2

使用​​檢查如果檢查...

buttons: { 
    Select: function() { 
     if ($("#chk").is(':checked')) { 
      $("#OrderNo").val($("#porderno").val()); 
     } 
    }, 
+0

老闆很高興看到您的代碼正在工作....但問題是,我想獲得訂單號的porderno值。我怎麼能做到這一點? – MNAH

+0

剛更新的答案。那是你在找什麼? –

+0

老闆它不工作...但我的概念是有.. – MNAH

0

檢查,如果複選框被選中jQuery,您可以通過

//will return true if the check box is checked otherwise false! 
$("#chkBoxId").is(':checked'); 

與單選按鈕/複選框組打交道時,這種做法是很好的做到這一點。

//will yield the same result if checkbox is checked 
$('input[name="chkBoxName"]:checked').val();  

所以,你可以在你的代碼中使用它們像什麼@Anthony Chu迴應,我正要寫:)