So I get no reaction what so ever from my chatapp created in asp mvc 5. I dont get any javascript errors according to chrome Console.
Got this line in my Startup in the Configuration method.
app.MapSignalR();
ChatHub class
public class ChatHub : Hub
{
public void Send(string name, string message)
{
// Call the broadcastMessage method to update clients.
Clients.All.broadcastMessage(name, message);
}
}
Chat view, The first line here below, works fine, ive seen it in the source. The last js line doesnt even get executed cause the textbox doesnt get cleared.
<input type="hidden" id="displayname" value="@User.Identity.GetUserName()" />
<ul id="realChat" class="chat">
<!-- MESSAGES GO HERE -->
</ul>
<!-- MESSAGE -->
<input id="btn-input" type="text" class="form-control input-sm" placeholder="Type your message here..." />
<span class="input-group-btn">
<!-- SEND BUTTON -->
<button class="btn btn-warning btn-sm" id="btn-chat">Send</button>
</span>
<script src="~/Scripts/jquery.signalR-2.2.0.min.js"></script>
<script src="~/signalr/hubs"></script>
<script type="text/javascript">
$(function () {
// Declare a proxy to reference the hub.
var chat = $.connection.chatHub;
// Create a function that the hub can call to broadcast messages.
chat.client.broadcastMessage = function (name, message) {
// Html encode display name and message.
var encodedName = text(name).html();
var encodedMsg = text(message).html();
// Add the message to the page.
$('#realChat').append(" <li class='clearfix'><div class='chat-body clearfix'> <strong style='color: red' class='primary-font'>"+encodedName+"</strong>:<span>"+encodedMsg+"Ls</span></div></li>");
};
// Set initial focus to message input box.
$('#btn-input').focus();
// Start the connection.
$.connection.hub.start().done(function () {
$('#btn-chat').click(function () {
// Call the Send method on the hub.
chat.server.send($('#displayname').val(), $('#btn-input').val());
// Clear text box and reset focus for next comment.
$('#btn-input').val('').focus();
});
});
});
</script>
Edit: Something's wrong in my view, i created a new html page and pasted all html from here http://www.asp.net/signalr/overview/getting-started/tutorial-getting-started-with-signalr and it worked. Still dont know what the problem is in my View