我有一个问题,我坚持。我有MVC 3应用程序,在这个应用程序中我有调查和培训的概念。每项培训都有1次调查。要让用户进行调查,请在单击HTML动作链接时打开弹出页面。以下是DetailsSurvey.cshtml中的代码:
<tr> <td class="view_detail_label">
Eğitim Adı
</td>
<td>
@Html.ActionLink(
training.Name.Name,
"AddSurvey",
new {
employeeId = Model.Id,
trainingId = training.Id
},
new {
@class = "addSurvey"
}
)
<div class="result" style="display:none;"></div>
</td>
</tr>
然后在javascript方面我有以下函数来打开弹出窗口:
$(document).ready(function () {
$('.addSurvey').click(function () {
$.ajax({
url: this.href,
type: 'GET',
cache: false,
context: this,
success: function (result) {
$(this).next('.result').html(result).dialog({
autoOpen: true,
title: 'Anket',
width: 500,
height: 'auto',
modal: true
}); //end of dialog
} //enf of success function
}); //end of ajax call
return false;
});
});
$(document).delegate('.addSurvey', 'click', function () {
$.ajax({
url: this.href,
type: 'GET',
cache: false,
context: this,
success: function (result) {
$(this).next('.result').html(result).dialog({
autoOpen: false,
title: 'Anket',
width: 500,
height: 'auto',
modal: true
}); //end of dialog
} //enf of success function
}); //end of ajax call
});
可以有一个或多个调查链接。当我单击按钮时弹出窗口第一次打开但是当我关闭弹出窗口并尝试重新打开时,它根本不会打开。如果我在新标签或窗口中打开它,它会分别打开。我使用delegate
订阅了该事件,但它不起作用。这是由关闭按钮采取的操作引起的,它在关闭后以某种方式失去了功能。有没有修复?
答案 0 :(得分:0)
<tr> <td class="view_detail_label">
Eğitim Adı
</td>
<td>
@Html.ActionLink(
training.Name.Name,
"AddSurvey",
new {
employeeId = Model.Id,
trainingId = training.Id
},
new {
@class = "addSurvey"
@onclick="javascript:OpenSurveyPopup();"
}
)
<div class="result" style="display:none;"></div>
</td>
</tr>
<script type="text/javascript">
function OpenSurveyPopup()
{
$.ajax({
url: this.href,
type: 'GET',
cache: false,
context: this,
success: function (result) {
$(this).next('.result').html(result).dialog({
autoOpen: true,
title: 'Anket',
width: 500,
height: 'auto',
modal: true
}); //end of dialog
} //enf of success function
}); //end of ajax call
return false;
});
}
</script>
还删除$(document).ready()和$(document).delegate()。 这会奏效。感谢。
答案 1 :(得分:0)
我使用以下实时函数解决了问题,我所做的是:在弹出窗口的关闭动作中,我调用了我的控制器并重新渲染页面,现在它就像魅力一样。
$('a.addSurvey').live('click', function (e) {
var $this = $(this);
e.preventDefault();
$.ajax({
url: this.href,
type: 'GET',
cache: false,
context: this,
success: function (result) {
$(this).next('.result').html(result).dialog({
autoOpen: true,
title: 'Anket',
width: 500,
height: 'auto',
modal: true,
close: function () { console.log("onClose"); $('.surveyTable').load('Home/DetailsSurvey', {id:@Model.Id}); }
}); //end of dialog
console.log($(this).next('.result'));
}, //enf of success function
complete: function () {
console.log("Complete");
},
error: function () {
console.log("Error");
}
}); //end of ajax call
}); //end of live