lundi 7 décembre 2015

partial view in a layout - unable to replace span text

I am working on setting up notification in the layout. I use partial view to display the notification below is my layout:

    <html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>@ViewBag.Title - My ASP.NET MVC Application</title>
        <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
        <link href="/Content/ABC.css" rel="stylesheet" />
        <meta name="viewport" content="width=device-width" />
        @Styles.Render("~/Content/css")
        @Scripts.Render("~/bundles/modernizr")
    </head>
    <body>
        <header>
                <div class="content-wrapper">
                    <div class="float-left">
                        <p class="site-title">@Html.ActionLink("your logo here", "Index", "Home")</p>
                    </div>
                 @Html.Partial("_Notification") //this is partail view
                        <div class="float-right">

and the partial view is as below.

 <div id="notification">
     @*   <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>*@
            <strong>
             <span style="padding-right:3px; padding-top: 3px; display:block;">
                <img src="../../Images/notification.jpg" />
        </span> : </strong>
    </div>
@section Scripts {
<script src="~/Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
    <script src="~/Scripts/jquery.signalR-1.1.4.js" type="text/javascript"></script>
    <script src="~/signalr/hubs"></script>
<script type="text/javascript">
    $(function () {
        var proxy = $.connection.notificationHub;
        var Count = 0;
        alert(1);
        proxy.client.receiveNotification = function (data) {
            for (var i = 0; i < data.length; i++) {
                var element = data[i];
                if (element.IsRead) {
                    Count = Count + 1;
                }

                $("#notification span").text("Unread messages");
            }
        };
        $.connection.hub.start();
    });


</script>
}

i am unable to replace the span text with the below code .i am using signal r hub class to send the notification. from my admin notification screen i am saving a text and in layout i am getting the count of the unread mesasges and will be dispalying there. Here once i hit save in the notification screen the count is not displaying in the layout

Aucun commentaire:

Enregistrer un commentaire