的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控制器操作方法不会触发。
注意:上面的ajax方法位于jquery UI弹出窗口
中那为什么?