I have a MVC project which has 2 button and 6 textbox. I want to call different methods on a Hub.
Client :
$(document).ready(function () { var bitcoinHub = $.connection.bitcoinHub; $("#btnBuy").click(function () { var tl = document.getElementById("bitcoinBuy").value; var btc = document.getElementById("aBitcoin").value; var total = document.getElementById("aTotal").value; bitcoinHub.server.trade("buy",@Model.user,tl,btc,total); }); bitcoinHub.client.broadcastSell = function (model) { // $("#sellGrid").append("<li>"+model.Sell+"</li>"); }; $("#btnSell").click(function () { var tl = document.getElementById("bitcoinSell").value; var btc = document.getElementById("sBitcoin").value; var total = document.getElementById("sTotal").value; bitcoinHub.server.trade("sell",@Model.user,tl,btc,total); }); bitcoinHub.client.broadcastPurchase = function (model) { // $("#buyGrid").append("<li>"+model.Buy+"</li>"); }; $.connection.hub.start(); }); In the case I press "btnBuy" or "btnCell" it should invoke the trade methode on the server with different parameters.
Server:
BitcoinHub(name) Class Method
public void trade(string parametre, Users cUser, string tl, string btc, string total) { switch (parametre) { case "sell": // Do something not important here break; case "buy": // Do something not important here break; } } In the case I press "btnBuy" or "btnCell" it goes trough the clickeventhandler. The problem is that the method on the hub will not be called.