我有AJAX脚本
这是代码
<script>
$(document).ready(function () {
$.ajax({
url: '@Url.Action("Profile_Data_Questions", "Interwier")',
contentType: 'application/json; charset=utf-8',
type: 'GET',
dataType: 'json',
processData: false,
success: function (data) {
var question1 = data[0];
$(".list").append('<div class="something" style="cursor: pointer;width:80%;font-size:20px;margin-top:15px;border-style: solid;border-color:#ffcf00;border-radius: 5px;margin: 10px auto 0;">' + question1.Question1 + '</div>' +
'<div class="something" style="cursor: pointer;width:80%;font-size:20px;margin-top:15px;border-style: solid;border-color:#ffcf00;border-radius: 5px;margin: 10px auto 0;">' + question1.Question2 + '</div>' +
'<div class="something" style="cursor: pointer;width:80%;font-size:20px;margin-top:15px;border-style: solid;border-color:#ffcf00;border-radius: 5px;margin: 10px auto 0;">' + question1.Question3 + '</div>' +
'<div class="something" style="cursor: pointer;width:80%;font-size:20px;margin-top:15px;border-style: solid;border-color:#ffcf00;border-radius: 5px;margin: 10px auto 0;">' + question1.Question4 + '</div>' +
'<div class="something" style="cursor: pointer;width:80%;font-size:20px;margin-top:15px;border-style: solid;border-color:#ffcf00;border-radius: 5px;margin: 10px auto 0;">' + question1.Question5 + '</div>' +
'<div class="something" style="cursor: pointer;width:80%;font-size:20px;margin-top:15px;border-style: solid;border-color:#ffcf00;border-radius: 5px;margin: 10px auto 0;">' + question1.Question6 + '</div>' +
'<div class="something" style="cursor: pointer;width:80%;font-size:20px;margin-top:15px;border-style: solid;border-color:#ffcf00;border-radius: 5px;margin: 10px auto 0;">' + question1.Question7 + '</div>' +
'<div class="something" style="cursor: pointer;width:80%;font-size:20px;margin-top:15px;border-style: solid;border-color:#ffcf00;border-radius: 5px;margin: 10px auto 0;">' + question1.Question8 + '</div>' +
'<div class="something" style="cursor: pointer;width:80%;font-size:20px;margin-top:15px;border-style: solid;border-color:#ffcf00;border-radius: 5px;margin: 10px auto 0;">' + question1.Question9 + '</div>' +
'<div class="something" style="cursor: pointer;width:80%;font-size:20px;margin-top:15px;border-style: solid;border-color:#ffcf00;border-radius: 5px;margin: 10px auto 0;">' + question1.Question10 + '</div>');
var divs = document.getElementsByTagName('div');
for (i = 0; i < divs.length; i++) {
if (divs[i].innerHTML == "") {
divs[i].style.display = 'none';
}
}
}
});
});
这是后端的代码:
public ActionResult Profile_Data_Questions()
{
var dataforprofile = TempData["FIO"];
var profiledataquestions = db.QuestionBlocks
.Where(x => x.Interview.Interwiers.Any(y => y.FIO == dataforprofile))
.Where(x => x.Question1 != null)
.Where(x => x.Question2 != null)
.Where(x => x.Question3 != null)
.Where(x => x.Question4 != null)
.Where(x => x.Question5 != null)
.Where(x => x.Question6 != null)
.Where(x => x.Question7 != null)
.Where(x => x.Question8 != null)
.Where(x => x.Question9 != null)
.Where(x => x.Question10 != null)
.Select(x => new
{
ID = x.Block_ID.ToString(),
Question1 = x.Question1,
Question2 = x.Question2,
Question3 = x.Question3,
Question4 = x.Question4,
Question5 = x.Question5,
Question6 = x.Question6,
Question7 = x.Question7,
Question8 = x.Question8,
Question9 = x.Question9,
Question10 = x.Question10,
})
.ToList();
return Json(profiledataquestions, JsonRequestBehavior.AllowGet);
}
我在View上有这个错误
无法读取未定义的属性'Question1'
我在后端代码上设置断点并写入数据
哪里有问题?
非常感谢你的帮助!