我正在尝试在Entity Framework中跟踪数据库表是否有新记录添加。如果数据库表中有任何新的记录添加,我只想从控制器获取记录。有什么建议吗?
[HttpGet]
public JsonResult DisplayChatMsgs()
{
var chatMsgs = dbObj.tblChats.ToList();
return Json(chatMsgs, JsonRequestBehavior.AllowGet);
}
客户:
$.ajax({
url: "Default/DisplayChatMsgs",
type: "Get",
success: function (data) {
//var mdata = $.parseJSON(data.d);
//The Div to be populated
$('#msgBox').empty();
content = "";
//Looping thru each record
$.each(data, function (i, record) {
//Properties available in Model
//We need to specify the properties in our model
content += "<tr><td><b>" + record.toName + "</b>:</td><td>" + record.chatMsg + "</td></tr>";
});
table = "<table>" + content + "</table>"
$(table).appendTo('#msgBox');
$("#msgBox").animate({ scrollTop: $('#msgBox')[0].scrollHeight }, 1000);
}
});