我必须做一个简单的验证,如果我在DropDownList
选择某人,我需要通过SignalR
向所有用户触发简单通知。
但代码无法正常工作,因为在此之后用户被重定向到另一个View,然后,通知不会出现。如果我不将表单提交给另一个视图,它就可以工作。
我希望即使表单已提交,我也需要在DropDownList
选择某人时通过SignalR显示我的通知,有人可以帮我这个吗?
的JavaScript
<script type="text/javascript">
function Signal() {
var chat2 = $.connection.redirecionarTarefa;
chat2.client.broadcastMessage = function (nome, mensagem) {
var htmlNotificacao =
"<div id='toast-container' class='toast-bottom-right'>"
+ " <div class='toast toast-info' style=''>"
+ " <button class='toast-close-button'>×</button>"
+ " <div class='toast-message'>Attention! Task redirect to " + mensagem + ".</div>"
+ " </div>"
+ "</div>";
$("body").append(htmlNotificacao);
};
$.connection.hub.logging = true;
$.connection.hub.start().done(function () {
if ($("#ddlAtribuir :selected").text() != "Select")
chat2.server.send("Lucas", $("#ddlAtribuir :selected").text());
}
});
}
</script>
HTML
@using (Html.BeginForm("Principal", "Home")) {
<div class="form-group">
<label class="col-sm-2 control-label" for="inputEmail3">Atribuir Para</label>
<div class="col-sm-9">
<select id="ddlAtribuir" class="ng-pristine ng-valid">
<option value="0" selected="selected">Select</option>
<option value="1">John Doe</option>
</select>
</div>
</div>
<input type="submit" class="btn btn-primary" onclick="Signal()" style="box-shadow: none;" value="Concluir" />
}