【发布时间】:2016-06-30 18:08:55
【问题描述】:
我正在构建 MVC 5,SignalR 实时通知应用程序,我想将我的工作脚本放在 _Layout.cshtml 中,因为例如在添加新项目时我想显示 toastr 通知,但脚本放置它 _Layout.cshtml 不起作用,我在 BundleConfig 中添加了脚本,但它不起作用。 注意:除了 _Layout.cshtml 之外的每个页面都可以正常工作 谁能帮我?非常感谢。 这是我的代码:
$(document).ready(function () {
toastr.options = {
"closeButton": true,
"debug": false,
"newestOnTop": false,
"progressBar": true,
"positionClass": "toast-top-right",
"preventDuplicates": false,
"showDuration": "300",
"hideDuration": "1000",
"timeOut": "5000",
"extendedTimeOut": "1000",
"showEasing": "swing",
"hideEasing": "linear",
"showMethod": "fadeIn",
"hideMethod": "fadeOut"
};
$(function () {
var notificationhub = $.connection.notificationHub;
notificationhub.client.displayMessage = function (message) {
toastr.success(message);
//$('#notification').html(message);
};
$.connection.hub.start();
}); });
如果我把它放在@section scripts{} 的任何页面上,这个脚本就可以工作
我的 _Layout 脚本部分如下所示:
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@Scripts.Render("~/bundles/notifications")
@RenderSection("scripts", required: false)
但是这种方式行不通。 如何在我的 _Layout 页面中正确实现我的脚本以显示通知。
【问题讨论】:
标签: razor asp.net-mvc-5