1

我的添加按钮有问题...我想要一个条件,如果网格中有相同的数据,如果单击添加按钮,则会弹出警报消息。但它发生在弹出警报消息后,添加按钮将被禁用。我在这个问题上停留了好几天。感谢有人会提供帮助。

html:

<div class="main">
        @using (Html.BeginForm("AvailabilitySave", "Worker", FormMethod.Post, new { id = "AvailabilityForm" }))

        {

            <input type="hidden" id="availabilityId" name="workerId" value="@workerId" />

          <p>
                    <label for="dllAvailableDay">
                        <abbr title="This is a required field.">
                            <em><font color="red">*</font></em></abbr>
                        Available Day</label>
                    <span>
                        @Html.DropDownList("dllAvailableDay", new SelectList(ViewBag.availableDayList, "ID", "Display_Value", workerAvailableDay), "[Please Select]",
              new Dictionary<string, object>
                    {
                        {"class","validate[required] inputLong"}
                    })
                    </span>
                </p>
                <p>
                    <label for="TpStartTime">
                        <abbr title="This is a required field.">
                            <em><font color="red">*</font></em></abbr>
                        Start Time</label>
                    <span>
                        <input id="tpStartTime" name ="tpStartTime" value="@workerStartTime" 
                               style="padding:0 0 0 0 !important" />
                    </span>
                </p>

                <p>
                    <label for="TpEndTime">
                        <abbr title="This is a required field.">
                            <em><font color="red">*</font></em></abbr>
                        End Time</label>
                    <span>
                        <input id="tpEndTime" name ="tpEndTime" value="@workerEndTime" 
                                style="padding:0 0 0 0 !important"/>
                    </span>
                  </p>
    <p>
                    <label>
                        Anytime</label>
                    <span>
                        <input type="checkbox" name="chAnytime" id="chAnytime" value="true" checked="checked" />
                    </span>
                </p>
                <p>
                    <span>
                        <input type="submit" id="addAvailBtn" class="styledButton" value="Add" />
                    </span>
                </p>
}
</div>

js:

$("#AvailabilityForm").on('submit', function (e) {

        var gvDetDDLs = $('#availabilityGrid').find("input[name=dllEditAvailableDay]");
        $.each(gvDetDDLs, function () {
            var duplicateExists = false;
            var ddlDay = $("#dllAvailableDay option:selected").text();
            var currVal = $(this).val();

            gvDetDDLs.not(this).each(function () {
                e.preventDefault();
                if (ddlDay == currVal) {
                    duplicateExists = true;
                    $(this).focus();
                    return false;
                }

            });
            if (duplicateExists) {
                alert("Duplicate entry is not allowed");
                return false;
                $('#addAvailBtn').prop('disabled', false);
            }

        });
        return true;
    });

网格:

$("#availabilityGrid").kendoGrid({
        scrollable: false,
        sortable: true,
        pageable: true,
        dataSource: {
            transport: {
                read: {
                    url: '/Worker/GetAvailabilityList?availabilityId=' + availabilityId,
                    dataType: "json",
                    type: "POST"
                }
            },
            change: function (e) {
                $(window.location.hash).click();
            },
            pageSize: 10
        },
        rowTemplate: kendo.template($("#availabilityTemplate").html().replace('k-alt', '')),
        altRowTemplate: kendo.template($("#availabilityTemplate").html())
    });

控制器:

private void GetAvailableDayList()
        {
            var availableDayList = (from a in db.Lookups
                                    where a.Domain == "AVAILABLEDAY"
                                    select a).ToList();

            ViewBag.AvailableDayList = availableDayList;
        }
4

0 回答 0