我有问题。我正在按照此处提到的方法进行操作:Progress bar for long running server calls in ASP.Net MVC,但是它不起作用。没有例外也没有错误,问题是什么也没做。为什么我的代码不向客户端报告进度?另一件事是我不知道为什么signalR无法生成脚本
<script src="~/signalr/hubs"></script>
控制器
ProgressHub.SendMessage("Iniciando proceso", 2);
启动类
using Microsoft.Owin;
using Owin;
using Microsoft.AspNet.SignalR;
[assembly: OwinStartup(typeof(DimexCEUI.Startup))]
namespace DimexCEUI
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
//ConfigureAuth(app);
app.MapSignalR();
}
}
}
我的中心
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Web;
using Microsoft.AspNet.SignalR;
namespace DimexCEUI
{
public class ProgressHub : Hub
{
public string msg = "Initializing and Preparing...";
public int count = 1;
public static void SendMessage(string msg, int count)
{
var message = "Proceso completado " + msg;
var hubContext = GlobalHost.ConnectionManager.GetHubContext<ProgressHub>();
hubContext.Clients.All.sendMessage(string.Format(message), count);
}
public void GetCountAndMessage()
{
Clients.Caller.sendMessage(string.Format(msg), count);
}
}
}
客户:
function StartInvoicing() {
var progressNotifier = $.connection.progressHub;
// client-side sendMessage function that will be called from the server-side
progressNotifier.client.sendMessage = function (message, count) {
// update progress
UpdateProgress(message, count);
alert(message);
};
// establish the connection to the server and start server-side operation
$.connection.hub.start().done(function () {
// call the method CallLongOperation defined in the Hub
progressNotifier.server.getCountAndMessage();
});
}
// Update the progress bar
function UpdateProgress(message, count) {
var result = $("#progress-data");
result.html(message);
$("#progress-count").html(count);
}