0
我有一個MVC4應用程序安裝程序來測試SignalR推送通知,哪個不工作。 (我已經在MVC官方網站上測試了聊天應用程序,並且它的工作完美,問題是當我從控制器推送消息時)。請有人幫我解決這個問題。SignalR與MVC4,無法從控制器上動作
(1)I具有啓動CS如下,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.Owin;
using Owin;
namespace MvcApplication3
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.MapSignalR();
}
}
}
(2)集線器類
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Hubs;
namespace MvcApplication3
{
[HubName("notificationHub")]
public class NotificationHub : Hub
{
}
}
(3)什麼IM上控制器操作的方式是,
public ActionResult Index()
{
SendMessage("This should be displayed on client !!");
return View();
}
private void SendMessage(string message)
{
var context = GlobalHost.ConnectionManager.GetHubContext<NotificationHub>();
context.Clients.All.viewMessage(message);
}
(4)最後在索引視圖,
<style type="text/css">
#span-display
{
color: red;
font-size: 16px;
}
</style>
<span id="span-display"></span>
@section scripts
{
<script src="~/Scripts/jquery.signalR-2.0.1.min.js"></script>
<script src="~/signalr/hubs"></script>
<script type="text/javascript">
$(function() {
var notificationhub = $.connection.notificationHub;
notificationhub.client.viewMessage = function (message) {
$('#span-display').html(message);
};
$.connection.hub.start();
});
</script>
}
請你幫我的傢伙,即時通訊上的最後期限,解決不了這一點。請原諒,如果這是一件簡單的事情,但對於這項技術來說是新的。
預先感謝您:-)
你能比「它不工作」更具體嗎? – user1618143
這意味着消息不會顯示爲我期望的跨度:-( – chamweer
'message'包含了什麼嗎?是否調用了viewMessage'函數? – pollirrata