簡體   English   中英

如何在mvc中獲取復選框值?

[英]How to get checkbox value in mvc?

當我將選中復選框並將單擊選擇按鈕如何將此值獲取到文本框值。 復選框id = chk和textbox id = OrderNo。 請幫助我....我在下面有一些東西....

$("#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>

使用.is(':checked')檢查是否已選中...

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

檢查是否在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已經回應了我要寫的:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM