2014-02-23 24 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回应,我正要写:)