0
에서 작동하지 않는 나는 내 ASP.NET 부분 파일에 다음 코드가 있습니다SignalR 코드는 ASP.NET MVC 부분 파일
<ul class="nav navbar-nav navbar-right">
<li><label id="message">No messages</label></li>
<li><input type="button" id="startButton" value="Start Monitoring" /></li> <!--Just for testing actual app won't have a button! -->
@section scripts {
<!--Script references. -->
<!--The jQuery library is required and is referenced by default in _Layout.cshtml. -->
<!--Reference the SignalR library. -->
<script src="~/Scripts/jquery.signalR-2.0.2.js"></script>
<!--Reference the autogenerated SignalR hub script. -->
<script src="~/signalr/hubs"></script>
<!--SignalR script to update the chat page and send messages.-->
<script>
$(function() {
// Reference the auto-generated proxy for the hub.
var testHub = $.connection.testHub;
// Create a function that the hub can call back to display messages.
testHub.client.displayMessages = function (message) {
// Add the message to the page.
$('#message').text(message);
};
// Start the connection.
$.connection.hub.start().done(function() {
$('#startButton').click(function() {
// Call the Send method on the hub.
testHub.server.listenToMessages(1);
});
});
});
</script>
}
ASP를. NET 부분 파일은 _Layout.cshtml 파일에서 템플릿의 _loginPartial.cshtml이 있던 곳에 맨 위에 표시됩니다.
시작 단추를 누를 때 허브 코드가 맞지 않는 것이 문제입니다. 동일한 코드는 Index.html에 배치하면 작동합니다.
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
나는 부분 파일 실 거예요 허브를 시작하는 이유는 어떤 생각을 : 나는 JQuery와는 아래와 같이 레이아웃 파일의 맨 위에 추가 한? 사용자가보기에 상관없이 맨 위에 표시 할 메시지를 갖고 싶습니다. 그래서 레이아웃 파일에 배치 할 부분 파일을 사용하고 싶습니다.