我无法在我的MVC应用程序中异步更新数据,但我对.net应用程序中的相同代码没有任何问题。它是一个链接到数据库的简单gridview,我希望每隔几秒更新一次gridview中的数据,而无需重新加载整个页面。它在.net应用程序中运行良好,但我在MVC中遇到以下错误:
“JavaScript运行时错误:Sys.WebForms.PageRequestManagerParserErrorException:无法解析从服务器收到的消息。”
实际页面是静态的,不会更新。如果我使用标准的Postback触发器,则错误消失,但我不想使用回发触发器,因为它只会导致整个页面重新加载。
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Livebids</title>
<script runat="server">
protected void OnTimerIntervalElapse(object sender, EventArgs e)
{
GridView1.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{ CurrentTime.Text = DateTime.Now.ToLongTimeString(); }
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:Label ID="CurrentTime" runat="server"></asp:Label>
<asp:ScriptManager ID="ScriptManager1" runat="server"/>
<asp:Timer runat="server" ID="ctlTimer"
Interval="1000" OnTick="OnTimerIntervalElapse" />
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1">
<Columns>
<asp:HyperLinkField DataNavigateUrlFields="Item_URL" DataTextField="Item"
Target="_blank" />
<asp:BoundField DataField="Bid" HeaderText="Bid" SortExpression="Bid" />
<asp:BoundField DataField="BPM" HeaderText="BPM" SortExpression="BPM" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:qbrdataConnectionString2w %>"
ProviderName="<%$ ConnectionStrings:qbrdataConnectionString2w.ProviderName %>"
SelectCommand="SELECT livebids.ID, livebids.ProductName, Max(livebids.BidPrice) AS 'Bid', count(livebids.Tstamp) AS 'BPM', scrape1_scraped.Item_URL, scrape1_scraped.item FROM livebids , scrape1_scraped WHERE livebids.ID = scrape1_scraped.ID AND livebids.Tstamp >= now() - interval 1 minute AND livebids.BidPrice > 0 group by livebids.ID ORDER BY scrape1_scraped.End_Time ASC limit 40;">
</asp:SqlDataSource>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ctlTimer" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
这在asp.net中运行良好,但MVC我得到错误,没有回发没有数据更新。