问题描述
在我的ASP.NET Mvc中,我决定使用Ajax更新我的局部视图。如果get方法成功,则它将传递的对象传递给@Html.Partial
方法。但是,在$("#Flashcards").html("@Html.Partial("_Flashcard",c)");
行中,它告诉我c does not exist in the current function.
<script>
$("#startReview").click(function () {
$.ajax({
type: "GET",url: "/VolunteerEvent/GetEvents",success: function (c) {
$("#Flashcards").html("@Html.Partial("_Flashcard",c)");
},error: function (error) {
$("#Flashcards").html("<p>You have no cards ready for review</p>")
}
})
});
</script>
我尝试添加一个对象,但是它仍然无法识别引用,并说card does not exist in the current function
<script>
var card;
$("#startReview").click(function () {
$.ajax({
type: "GET",success: function (c) {
card = {
Id: c.Id,CardFront: c.CardFront,CardBack: c.CardBack,Deck: c.Deck
};
$("#Flashcards").html("@Html.Partial("_Flashcard",card)");
},error: function (error) {
$("#Flashcards").html("<p>You have no cards ready for review</p>")
}
})
});
</script>
解决方法
您可以在成功获取请求中为部分视图添加发布请求。
TcpStream::connect_timeout()