0

Javascript/Jquery:

            specialInsDialog.dialog('open');

            specialInsDialog.find('#buttonSave').live('click', function () {

                function addSpecialInstuction(spinstructionVal, isYesVal) {

                    $.ajax({
                        type: "POST",
                        url: "/Portal/AddSpecialInstuction",
                        dataType: 'json',
                        data: { providerKey: selProviderKey, ownerKey: selOwnerKey, petKey: selPetKey, instruction: spinstructionVal, isPermenant: isYesVal, invoiceId: selInvoiceId },
                        success: function (data) {
                            alert('sam');
                        }
                    });
                }

                var chkBox = document.getElementById('checkboxSpecialIns');

                if (chkBox.checked) {

                    var oTable = document.getElementById('table');
                    var rowLength = oTable.rows.length;

                    for (i = 1; i < rowLength; i++) {

                        var oCells = oTable.rows.item(i).cells;
                        var isYes = oCells[1].childNodes[0].checked;
                        var spinstruction = oCells[2].childNodes[0].value;

                        if (typeof (spinstruction) != 'undefined' && spinstruction != '') {

                            addSpecialInstuction(spinstruction, isYes);
                        }
                    }
                }
});

控制器 :

        [HttpPost]
        public JsonResult AddSpecialInstuction(string providerKey, string ownerKey, string petKey, string instruction, bool isPermenant, string invoiceId)
        {
            char[] delimiter = {'+'};
            string[] petKeys = petKey.Split(delimiter);
            Pet pet = null;  

            foreach (var key in petKeys)
            {
                pet = BasicRepository.GetPet(ownerKey, key);
                if (pet.SpecialInstructions != null && pet.SpecialInstructions.Where(a => a.Instruction.Trim() == instruction.Trim()).Count() <= 0)
                {
                    pet.AddSpecialInstruction(new SpecialInstruction()
                                                  {
                                                      Instruction = instruction,
                                                      IsPermenant = isPermenant,
                                                      PetId = pet.Id,
                                                      InvoiceId = isPermenant ? Guid.Empty : Guid.Parse(invoiceId)
                                                  });
                    BasicRepository.Save();
                }        
            } 
            Confirm("Your Special Instruction has been added.");
            return Json(string.Empty, JsonRequestBehavior.AllowGet);
        }

addSpecialInstuction只有在使用 firebug 运行代码时才会触发上述类型的代码和方法。没有 firebug 控制器的 Action 方法不会触发。

注意:上面的 ajax 方法在 jquery UI 弹出窗口中

那为什么?

4

0 回答 0