我在部分视图的顶部有以下 Javscript:
<script>
$(document).ready(function () {
alert('@Model.Course.CompletionTypeID');
$('#Submit').live('click', function () {
if ('@Model.Course.CompletionTypeID' == 2 || '@Model.Course.CompletionTypeID' == 3) {
alert("IN THE LOOP");
var fullURL = document.URL;
fullURL = fullURL.replace("#", "");
var courseID = fullURL.split('courseID=');
var courseID = courseID[1];
var postData = { 'courseID': courseID };
$.post('/Course/FinishSurvey/', postData, function (data) {
alert("COOL");
$('#finishDiv').hide();
$('#finishCompleteDiv').show();
alert("COOL COOL");
document.getElementById("FinishButton").style.visibility = "hidden";
document.getElementById("LaunchButton").style.visibility = "visible";
});
}
event.cancelBubble = true;
event.returnValue = false;
event.preventDefault();
event.stopPropagation();
});
});
</script>
单击“提交”按钮后,我收到“在循环中”的警报,因此我已成功进入循环,但随后在 if 语句顶部出错,因为由于某种原因我无法解决 post 方法似乎不是尽管代码是从工作页面复制的,但仍受到打击。它在以下行出错:
if ('@Model.Course.CompletionTypeID' == 2 || '@Model.Course.CompletionTypeID' == 3) {
即使它已经进入这个循环并找到了这个模型变量的值。如果我在调试时按 F5,它将移至 Course/FinishSurvey 控制器方法,但如果不按 F5,我将无法到达这一点。任何人都可以告诉我,如果你看到我做错了什么,任何帮助将不胜感激