【发布时间】:2014-03-28 16:56:15
【问题描述】:
我有默认的 Visual Studio 2013 MVC 模板。在我使用 ASP.NET Identity 登录并导航到我创建的 Match.cshtml 页面后,我收到一个错误“JavaScript 运行时错误:'$' 未定义”,该页面如下所示。任何想法为什么它没有看到 jquery '$'?
[编辑] 如果我制作一个普通的 HTML 页面,一切正常,所以这一定与使用布局或周围的东西有关。我正在使用默认模板 _Layout 页面。
@using Microsoft.AspNet.Identity
@if (Request.IsAuthenticated)
{
<!--Script references. -->
<!--Reference the jQuery library. -->
<script src="Scripts/jquery-2.1.0.min.js"></script>
<!--Reference the SignalR library. -->
<script src="Scripts/jquery.signalR-2.0.3.min.js"></script>
<!--Reference the autogenerated SignalR hub script. -->
<script src="signalr/hubs"></script>
<!--Add script to update the page and send messages.-->
<script type="text/javascript">
$(function () {
var clientID = "";
var server = $.connection.gameServer;
// Create a function that the hub can call to broadcast messages.
server.client.broadcastMessage = function (name, message) {
// Html encode display name and message.
var encodedName = $('<div />').text(name).html();
var encodedMsg = $('<div />').text(message).html();
// Add the message to the page.
$('#discussion').append('<li><strong>' + encodedName
+ '</strong>: ' + encodedMsg + '</li>');
};
// get the ID from the server for our team
server.client.responseID = function (id) {
clientID = id;
}
// Start the connection.
$.connection.hub.start().done(function () {
server.server.requestID();
// todo: define all the GUI events that need to send requests to the server for validation
$('#sendmessage').click(function () {
// Call the Send method on the hub.
server.server.send($('#displayname').val(), $('#message').val());
// Clear text box and reset focus for next comment.
$('#message').val('').focus();
});
});
});
</script>
}
else
{
<div>Please login!</div>
}
【问题讨论】:
标签: asp.net signalr asp.net-identity