Код: Выделить всё
$('.imageLandscapeFloatLeft').on('click', function () {
var vIDString = this.getAttribute('id');
if (vIDString.indexOf("image_") >= 0) {
var vID = vIDString.substring(6);
if ($.isNumeric(vID)) {
jQuery.ajax({
url: '@Url.Action("ReturnSoftwareImage", "Business")',
type: 'POST',
data: { ImageID: vID },
success: function (response) {
if (typeof (response) == 'object') {
var vAlt = (response.alt);
var vLink = (response.link);
ModalInformation(vAlt, vLink);
}
else {
ModalError(response);
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
ModalError(textStatus + " - " + errorThrown);
}
})
}
}
Она работает нормально, но поскольку эту функцию использует очень много страниц, я хотел упростить код и выделить фрагмент _Layout и просто передайте ему параметры вот так...
Код: Выделить всё
$('.imageLandscapeFloatLeft').on('click', function () {
var vIDString = this.getAttribute('id');
if (vIDString.indexOf("image_") >= 0) {
OpenImageModal("Business", "ReturnImage", "ReturnWebImage", vIDString, "6");
}
Код: Выделить всё
function OpenImageModal(ControllerName, ActionResultName, ActionData, IDString, IDLength) {
var vID = IDString.substring(IDLength);
if ($.isNumeric (vID)) {
alert(vID);
jQuery.ajax({
url: '@Url.Action()',
type: 'POST',
data: { ActionData: vID },
success: function (response) {
if (typeof (response) == 'object') {
var vAlt = (response.alt);
var vLink = (response.link);
ModalInformation(vAlt, vLink);
}
else {
ModalError(response);
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
ModalError(textStatus + " - " + errorThrown);
}
})
}
Подробнее здесь: https://stackoverflow.com/questions/790 ... ion-in-mvc
Мобильная версия